s = {1, 2, 3}
[Link](4)
[Link](2)
print("Set after operations:", s)
Set after operations: {1, 3, 4}
s = {'apple', 'banana', 'cherry'}
for item in s:
print(item)
apple
banana
cherry
s = {10, 20, 30, 40}
print("Length of set:", len(s))
Length of set: 4
t = (5, 10, 15, 20)
print("Second item of tuple:", t[1])
Second item of tuple: 10
d = {0: 10, 1: 20}
d[2] = 30
print(d)
{0: 10, 1: 20, 2: 30}
s = {3, 6, 2, 8, 4}
print("Max:", max(s))
print("Min:", min(s))
Max: 8
Min: 2
t = (1, 2, 3)
t += (4,)
print(t)
(1, 2, 3, 4)
t = ('P', 'y', 't', 'h', 'o', 'n')
s = ''.join(t)
print("String:", s)
String: Python
a = {1, 2, 3}
b = {2, 3, 4}
print("Intersection:", a & b)
Intersection: {2, 3}
a = {1, 2, 3}
b = {3, 4, 5}
print("Union:", a | b)
Union: {1, 2, 3, 4, 5}
d = {'a': 1, 'b': 2}
key = 'b'
print(key in d)
True
d = {'apple': 3, 'banana': 1, 'cherry': 2}
print("Ascending:", dict(sorted([Link](), key=lambda item: item[1])))
print("Descending:", dict(sorted([Link](), key=lambda item: item[1],
reverse=True)))
Ascending: {'banana': 1, 'cherry': 2, 'apple': 3}
Descending: {'apple': 3, 'cherry': 2, 'banana': 1}
a = {1, 2, 3}
b = {2, 4}
print("Difference:", a - b)
print("Symmetric Difference:", a ^ b)
Difference: {1, 3}
Symmetric Difference: {1, 3, 4}
result = [(x, x**2) for x in range(1, 6)]
print(result)
[(1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
t = (10, 20, 30)
a, b, c = t
print(a, b, c)
10 20 30
t = (1, 2, 3, 4, 5, 6, 7, 8)
print("4th from front:", t[3])
print("4th from last:", t[-4])
4th from front: 4
4th from last: 5
t = (1, 2, 2, 3, 4, 4, 4)
repeats = [x for x in set(t) if [Link](x) > 1]
print("Repeated items:", repeats)
Repeated items: [2, 4]
t = (10, 20, 30)
print(20 in t)
True
dic1 = {1: 10, 2: 20}
dic2 = {3: 30, 4: 40}
dic3 = {5: 50, 6: 60}
result = {**dic1, **dic2, **dic3}
print(result)
{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
s1 = {1, 2, 3}
s2 = [Link]()
print("Original:", s1)
print("Copy:", s2)
Original: {1, 2, 3}
Copy: {1, 2, 3}
from collections import Counter
d1 = {'a': 100, 'b': 200, 'c': 300}
d2 = {'a': 300, 'b': 200, 'd': 400}
result = Counter(d1) + Counter(d2)
print(result)
Counter({'a': 400, 'b': 400, 'd': 400, 'c': 300})