Test collections expt dict.

This commit is contained in:
Captain ALM 2022-11-30 18:53:27 +00:00
parent 6b4b7fbff3
commit 6cb9ab5109
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

72
main.py
View File

@ -1,3 +1,69 @@
a = {1, 2}
b = {"a":1, "b":2}
print(type(a), type(b))
#Test collection stuff
a=[1,2,3]
b=[4,5]
print(a, b)
a.append(4)
print(a)
a.remove(4)
print(a)
a.extend(b)
print(a)
a.pop(3)
print(a)
a.insert(3,4)
del a[0]
print(a)
del a[1:3]
print(a)
del a
print(b.clear())
print(b)
c = [1, 2, 3, 4, 5,6, 7]
d = [print(x) for x in c]
print(d)
#x = [expr_fill_list for item in itr if cond == True]
#Condition is optional
e = [x for x in c if x%2 == 1]
print(e)
f = [x if x%2 == 1 else None for x in c]
print(f)
c.sort(reverse=True)
print(c)
c.sort()
print(c)
def sk(n):
return n%2 == 0
#key defines the function that provides the values for sorting
c.sort(key=sk)
print(c)
d = c.copy()
e = list(c)
d.clear()
e.insert(1, "A")
print(e)
print(d)
print(c)
b.extend((4,5,6,7,8))
print(b)
#* Means stick any remaining values as a collection in this variable, however the variables are still populated in order
*g, h, i = b
print(g,h,i)
j = (1, 2)
k = (3, 4, 5)
l = j + k
print(l)
print(k*3+l)
m = {1, 2, 3}
n = {3, 4, 5}
o = m.union(n)
print(o)
n.update(m)
print(n)
m = {1, 2, 3}
n = {3, 4, 5}
p = m.symmetric_difference(n)
print(p)
o = m.intersection(n)
print(o)
n.intersection_update(m)
print(n)