From 6cb9ab510975e9f8b0a66876acdec8c0a1cc9b22 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Wed, 30 Nov 2022 18:53:27 +0000 Subject: [PATCH] Test collections expt dict. --- main.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 13973a8..ebf70a3 100644 --- a/main.py +++ b/main.py @@ -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)