[Tutor] using dictionaries
Curt Hamblin
chamblin850 at gmail.com
Thu Mar 19 15:52:48 EDT 2020
I'm not the sharpest knife in the drawer, but I cannot understand why
one works and the other doesn't
-------------- next part --------------
parts_in_inv_dict
{37163: 2, 37869: 3, 37871: 2, 39331: 5, 39385: 1, 40172: 1, 40181: 1, 40525: 4, 40764: 1, 40864: 1, 40868: 1, 40869: 1, 40871: 2, 40885: 4, 40887: 2, 41921: 1, 42297: 1, 46070: 1, 46078: 2, 46088: 1, 46089: 2, 47083: 1, 49127: 2, 54851: 1, 54857: 1, 54862: 1, 54863: 1, 55025: 1, 55148: 1, 55614: 1, 56725: 1}
need = {}
need[40885] = 9
need[37869] = 3
need[46041] = 1
print ('Need dictionary = ',need)
print('Belt Counter == ', belt_dict)
Need dictionary = {40885: 9, 37869: 3, 46041: 1}
Belt Counter == Counter({'40885': 9, '37869': 3, '46041': 1})
print (' ================================================')
#print('Need')
print('Uses Need dictionary -----------------------------')
for x_key,y_value in need.items():
print(x_key,y_value)
print(inv_dict.get(x_key,' no idea why this does NOT work'))
print(x_key,y_value,inv_dict.get(x_key,'Not in inventory'))
print()
print ( '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=---')
c = belt_dict
dict(c)
print('Uses belt_dict Counter ')
for x_key,y_value in c.items():
print(x_key,y_value)
print(inv_dict.get(x_key,' key only'))
print(x_key,y_value,inv_dict.get(x_key,'Not in inventory'))
print()
results of running this code
Uses Need dictionary ---- Works as expected -------------------------
40885 9
4
40885 9 4
37869 3
3
37869 3 3
46041 1
no idea why this does NOT work
46041 1 Not in inventory
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=---
Does NOT Work
Uses belt_dict Counter
40885 9
key only
40885 9 Not in inventory
37869 3
key only
37869 3 Not in inventory
46041 1
key only
46041 1 Not in inventory
More information about the Tutor
mailing list