Test single-line if.

This commit is contained in:
Captain ALM 2022-11-30 18:54:52 +00:00
parent 6cb9ab5109
commit 3b7b4a6dd3
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

74
main.py
View File

@ -1,69 +1,5 @@
#Test collection stuff #1 Line Ifs
a=[1,2,3] x = None
b=[4,5] if x is None: print("Oh")
print(a, b) #x = " "
a.append(4) print("Why") if x is None else print ("No")
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)