Python Play
Jump to navigation
Jump to search
1a
https://www.nylas.com/blog/use-python-requests-module-rest-apis/
query = {'lat':'45', 'lon':'180'} r = requests.get('http://api.open-notify.org/iss-pass.json', params=query) print(r.json()) print(r.content, r.text, r.json)
2a
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