Python Play
Jump to navigation
Jump to search
Palidrome
def is_palidrome(string): string_alpha = "" for char in string: if char.isalpha(): string_alpha += char string_alpha_lower = string_alpha.lower() if(string_alpha_lower == string_alpha_lower[::-1]): print(f'The string "{string_alpha_lower}" is a palindrome.') return True else: print(f'The string "{string_alpha_lower}" is not a palindrome.') return False # string = input(("Enter a string:")) string = "No, Hannah, 11 !! on" is_palidrome(string)
1a
query = {'lat':'45', 'lon':'180'} r = requests.get('http://api.open-notify.org/iss-pass.json', params=query) data = r.json() for k,v in data.items(): print(k, v) for i in data['people']: print(i['craft'])
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