list(range(10,20,3))
[10, 13, 16, 19]
for x in range(3):
for y in range(4):
print(x,y)
0 0 0 1 0 2 0 3 1 0 1 1 1 2 1 3 2 0 2 1 2 2 2 3
for x in range(3):
for y in range(x,4):
print(x,y)
0 0 0 1 0 2 0 3 1 1 1 2 1 3 2 2 2 3
p1 = [(5,3),(8,2),(9,3),(6,0)]
def list_to_dict(p):
result = {}
for x in p:
if x[1] in result:
result[x[1]] = result[x[1]] + x[0]
else:
result[x[1]] = x[0]
return result
list_to_dict(p1)
{3: 14, 2: 8, 0: 6}
def dict_to_list(d):
result = []
for e in d:
result.append((d[e],e))
return result
dict_to_list({3: 14, 2: 8, 0: 6})
[(14, 3), (8, 2), (6, 0)]
def file_string_to_list(s):
xs = s.split(",")
result = []
for y in xs:
z = y.split(":")
result.append((int(z[0]),int(z[1])))
return result
file_string_to_list("5:3,8:2,9:3,6:0")
[(5, 3), (8, 2), (9, 3), (6, 0)]
with open("hello.txt","w") as f:
f.write("Hello, how are you?\n")
f.write("I am fine.\n")
f.close()