Untitled
unknown
plain_text
2 years ago
1.9 kB
6
Indexable
set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70}
# Removing items from set1 that are not common to both set1 and set2
set1.intersection_update(set2)
# Displaying the updated set1
print("Updated set1:", set1)
def reverse_tuple(input_tuple):
reversed_list = list(input_tuple)[::-1]
return tuple(reversed_list)
input_tuple = (1, 2, 3, 4, 5)
reversed_tuple = reverse_tuple(input_tuple)
print("Original Tuple:", input_tuple)
print("Reversed Tuple:", reversed_tuple)
def swap_numbers_without_temp(a, b):
a, b = b, a
return a, b
num1 = 5
num2 = 10
num1, num2 = swap_numbers_without_temp(num1, num2)
print("After swapping: num1 =", num1, "num2 =", num2)
tuple1 = ("Orange", [10, 20, 30], (5, 15, 25))
value_20 = tuple1[1][1]
print("Value 20 from the tuple:", value_20)
tuple1[1][1] = 220
print("Modified tuple:", tuple1)
tuple1 = (10, 20, 30, 20)
a, b, c, d = tuple1
print("a =", a)
print("b =", b)
print("c =", c)
print("d =", d)
count_20 = tuple1.count(20)
print("Count of 20:", count_20)
sample_list = ["Blue", "Green", "Red"]
sample_set = {"Yellow", "Orange", "Black"}
sample_set.update(sample_list)
print("Updated sample_set:", sample_set)
set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70}
identical_items = set1.intersection(set2)
unique_items = set1.union(set2)
print("Identical items from both sets:", identical_items)
print("Unique items from both sets:", unique_items)
set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70}
set1.intersection_update(set2)
print("Updated set1:", set1)Editor is loading...
Leave a Comment