Python Play

From UVOO Tech Wiki
Revision as of 17:32, 30 September 2021 by Busk (talk | contribs)
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)
print(r.headers["date"]) 

r = requests.post('https://httpbin.org/post', data = {'key':'value'})
requests.put('https://httpbin.org/put', data = {'key':'value'})

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