Difference between revisions of "Python Play"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "# 1 ``` [d['value'] for d in l] ``` # 2 ``` list1 = ["a", "b" ,"c"] # a bunch of things dictionary1 = {"a":1, "b":2, "c":3} # like a list but each part of it has an associat...")
 
Line 6: Line 6:
 
# 2
 
# 2
 
```
 
```
list1 = ["a", "b" ,"c"] # a bunch of things
+
list1 = ["a", "b" ,"c"]
dictionary1 = {"a":1, "b":2, "c":3} # like a list but each part of it has an associated extra bit
+
dictionary1 = {"a":1, "b":2, "c":3}
 
```
 
```
  

Revision as of 15:51, 30 September 2021

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