Difference between revisions of "Python Play"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 8: Line 8:
 
     if k == 'a':
 
     if k == 'a':
 
       print(i)
 
       print(i)
 +
 +
[d for d in ld][1]
 
```
 
```
  

Revision as of 16:45, 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:
    if k == 'a':
      print(i)

[d for d in ld][1]

1

[d['value'] for d in l]

2

list1 = ["a", "b" ,"c"]
dictionary1 = {"a":1, "b":2, "c":3}

3

[d['value'] for d in l]

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}

5

[d['value'] for d in l if 'value' in d]

6

a

7

a