Skip to content

Instantly share code, notes, and snippets.

inv = {'gold coin':42, 'rope':1}
dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1}
def add_to_inventory(inventory, added_items):
for item, value in added_items:
if item not in inventory:
inventory[item] = inventory.items(item, value) + 1
else:
inventory[item] = 0
print(inventory)
inv = {'gold coin':42, 'rope':1}
dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1}
def add_to_inventory(inventory, added_items):
for item, value in added_items:
inventory[item] = inventory.items(item, value) + 1
print(inventory)
test1 = { 'cat' : 1, 'dog' : 1, 'bird' : 1}
#test2 = { 'cat' : 3, 'dog' : 2, 'cow' : 2 }
test2 = [ 'cow', 'cow', 'cow', 'sheep', 'dog', 'rat' ]
for item in test2:
test1[item] = test1.get(item, 0) + 1
print(str(test1))
test1 = { 'cat' : 1, 'dog' : 1, 'bird' : 1}
test2 = { 'cat' : 3, 'dog' : 2, 'cow' : 2 }
for key, value in test2.items():
test1[key] = test2.get(key, 0) + 1
print(test1)
test1 = { 'cat' : 1, 'dog' : 1, 'bird' : 1}
test2 = { 'cat' : 3, 'dog' : 2, 'cow' : 2 }
for key, value in test1.items():
test1[key] = test2.get(key, 0) + test1[key]
print(test1)
test1 = { 'cat' : 1, 'dog' : 1, 'bird' : 1}
test2 = { 'cat' : 3, 'dog' : 2, 'cow' : 2 }
for key, value in test2.items():
test1[key] = test1.get(key, 0) + test2[key]
print(test1)
test1 = { 'cat' : 1, 'dog' : 1, 'bird' : 1}
test2 = { 'cat' : 3, 'dog' : 2, 'cow' : 2 }
for key in test2.items():
test1[key] = test1[key] + test2[key]
print(test1)
my_dic = { 'Jill' : 1, 'jason' : 3, 'amanda' : 4 }
my_dic2 = { 'Jill' : 2, 'jason' : 3, 'amanda' : 5, 'derek' : 3}
for key in my_dic2:
my_dic = my_dic2.get(key, 0) + my_dic
print(my_dic)
python: /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python3.5m-config
/usr/bin/python /usr/bin/python3.5-config /usr/lib/python2.7 /usr/lib/python3.5 /etc/python2.7
/etc/python3.5 /etc/python /usr/local/lib/python2.7 /usr/local/lib/python3.5 /usr/include/python3.5
/usr/include/python3.5m /usr/share/python /usr/share/man/man1/python.1.gz
[1]+ Stopped python3
gwith@Gwith-PC:~$ python2
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pyperclip
>>> pyperclip.copy('Hello world!')
>>> pyperclip.paste()
u'Hello world!'