Difference between revisions of "Python Play"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
+ | # 1 | ||
+ | |||
+ | ``` | ||
+ | ld = [{'a': 1, 'b': 2, 'c': 3}, {'a': 4, 'b': 5, 'c': 6}] | ||
+ | |||
+ | ``` | ||
+ | for d in ld: | ||
+ | for i in d: | ||
+ | print(i) | ||
+ | ``` | ||
+ | |||
# 1 | # 1 | ||
``` | ``` |
Revision as of 16:42, 30 September 2021
1
ld = [{'a': 1, 'b': 2, 'c': 3}, {'a': 4, 'b': 5, 'c': 6}]
for d in ld:
for i in d: print(i)
<br /># 1
[d['value'] for d in l]
<br /># 2
list1 = ["a", "b" ,"c"] dictionary1 = {"a":1, "b":2, "c":3}
<br /># 3
[d['value'] for d in l]
<br /># 4
def to_dictionary(keys, values):
return dict(zip(keys, values))
keys = ["a", "b", "c"]
values = [2, 3, 4]
print(to_dictionary(keys, values)) # {'a': 2, 'c': 4, 'b': 3}
<br /># 5
[d['value'] for d in l if 'value' in d]
<br /># 6
a
<br /># 7
a ```