4 built-in data types Flashcards
1
Q
Create dict from 1 list by list compr:
ls1 = [‘alma’, ‘körte’, ‘szilva’]
ls2 = [23, 10, 45]
A
d = {ls1[i]:ls2[i] for i in range(len(ls1))}
# print(d)
2
Q
Create dict from 1 list by zip
ls1 = [‘alma’, ‘körte’, ‘szilva’]
ls2 = [23, 10, 45]
A
res = dict(zip(ls1, ls2))
print(res)
3
Q
Create dict from 1 list by for loop in for loop
ls1 = [‘alma’, ‘körte’, ‘szilva’]
ls2 = [23, 10, 45]
A
res = {}
for i in ls1:
for j in ls2:
res[i] = j
ls2.remove(j)
break
print(res)
4
Q
Print this:
[‘a’, ‘b’, ‘c’]
[1, 2, 3]
Out of:
matrix = [[‘a’,’b’,’c’], [1,2,3], [4,5,6], [7,8,9]]
A
print(matrix[0], matrix[1], sep= ‘\n’)