print(accumulate) # pprint() qt = OrderedDict([ ('Moe', 'A wise guy, huh?'), ('Larry', 'Ow!'), ('Curly', 'Nyuk nyuk!'), ]) print(qt) pprint(qt) # Things Do # 5.1 import zoo print(zoo.hours()) # 5.2 import zoo as menagerie print(menagerie.hours()) # 5.3 from zoo import hours print(hours()) # 5.4 from zoo import hours as info print(info()) # 5.6 plain = {'a': 1, 'b': 2, 'c': 3}
#Problem 5.1: Make a file called zoo.py. In it define a function called hours that prints the string 'Open 9-5 daily'. Then, use the interpreter to import the zoo module and call its hours function. #where zoo.py is: def hours(): print('Open 9-5 daily') import zoo zoo.hours() #Problem 5.2: In the interpreter, import the zoo module as menagerie and call its hours function #where zoo.py is: def hours(): print('Open 9-5 daily') import zoo as menagerie menagerie.hours() #Problem 5.3: Import the hours function directly from zoo and call it. from zoo import hours hours() #Problem 5.4: Import the hours() function as info and call it from zoo import hours as info info() #Problem 5.5: Make a dictionary called plain with the key-vlaue pairs 'a':1,'b':2,'c':3 and print it. plain = {'a':1,'b':2,'c':3} print(plain) #Problem 5.6: Make an OrderedDict called fancy from the same pairs and print it. from collections import OrderedDict fancy = OrderedDict([('a',1),('b',2),('c',3)])
# from zoo import hours import zoo zoo.hours()
import zoo as menagerie print(menagerie.hours())
from zoo import hours print(hours())
import zoo as menagerie menagerie.hours() # result # # Open 9-5 daily
#4. import module as another name 'playpen' import zoo as playpen playpen.hours()
def doTheThing(): import zoo as menagerie print('---Thing 2---') menagerie.hours()
#3. Call hours() in zoo import zoo zoo.hours()
from zoo import hours hours()
def doTheThing(): print('---Thing 3---') from zoo import hours hours()
# 5-1 import zoo zoo.hours() # 5-2 import zoo as managerie managerie.hours() # 5-3 from zoo import hours hours() # 5-4 from zoo import hours as info info() # 5-5 plain = {"a": 1, "b": 2, "c": 3} print(plain) # 5-6 from collections import OrderedDict fancy = OrderedDict([("a", 1), ("b", 2), ("c", 3)]) print(fancy) # 5-7 from collections import defaultdict dict_of_lists = defaultdict(list) dict_of_lists["a"].append("something for a") print(dict_of_lists["a"])
import zoo print(zoo.hours())
def doTheThing(): import zoo print('---Thing 1---') zoo.hours()
import zoo as playpen playpen.hours()
#5.1 import zoo zoo.hours() #5.2 import zoo as menagerie menagerie.hours() #5.3 from zoo import hours hours() #5.4 from zoo import hours as info info() #5.5 plain = {'a': 1, 'b': 2, 'c': 3} print(plain) #5.6 from collections import OrderedDict fancy = OrderedDict([ ('a', 1), ('b', 2), ('c', 3) ]) print(fancy) #5.7 from collections import defaultdict dict_of_lists = defaultdict(list) dict_of_lists['a'].append('something for a') print(dict_of_lists['a'])