Created
September 19, 2019 23:50
-
-
Save pigeonflight/2e1d40caa0a3ed91d326b1c58e831059 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("hello world") | |
# Strings | |
my_string = "a string is here" | |
# Lists | |
my_list = ['2',1,5,"hello"] | |
# Dictionaries | |
my_dictionary = {"name":"David", | |
"age":120} | |
print(my_dictionary) | |
# forloops | |
for item in my_list: | |
print(item) | |
# list comprehension | |
new_list = ["this is: {}".format(item) | |
for item | |
in my_list | |
if len(str(item)) > 1 | |
] | |
print(new_list) | |
story_stuff = {"place":"garage","thing":"spanner"} | |
places = ["garage","bedroom","kitchen","under the sea","kfc","heaven","bottomless pit"] | |
things = ["leaf","carpenter","ostrich","elbow","door","large hadron collider","undergarment"] | |
places_things_dict = dict(zip(places, things)) | |
print(places_things_dict) | |
# | |
""" | |
{'garage': 'leaf', | |
'bedroom': 'carpenter', 'kitchen': 'ostrich', | |
'under the sea': 'elbow', | |
'kfc': 'door', | |
'heaven': 'large hadron collider', | |
'bottomless pit': 'undergarment'} | |
""" | |
thing_list = [{"place":key, | |
"thing":places_things_dict[key]} | |
for key | |
in places_things_dict.keys()] | |
#{"place":...,"thing":...} | |
print(thing_list) | |
# "path: {path} curr: {curr} prev: {prev}".format(**mydict) | |
for thing_dict in thing_list: | |
story_template = """ | |
Once upon a time in a {place} far away, | |
there lived a {thing}. | |
""".format(**thing_dict) | |
print(story_template) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment