[Tutor] using dictionaries
David L Neil
PyTutor at DancesWithMice.info
Thu Mar 19 18:10:30 EDT 2020
On 20/03/20 8:52 AM, Curt Hamblin wrote:
> I'm not the sharpest knife in the drawer, but I cannot understand why
> one works and the other doesn't
Before causing us to sharpen our knives (the Ides of March has passed!),
please copy-paste your code and any error messages (Tracebacks), ie
straight from the terminal window into the email msg.
There are a number of inconsistencies in the code-presented, and it is
confused by in-line comments which are not preceded by #
eg "Belt Counter == Counter({'40885': 9, '37869': 3, '46041': 1})" is
not legal Python and requires the collections library be imported (I assume)
add to the above line of 'code':
c = belt_dict
dict(c)
print('Uses belt_dict Counter ')
and the multiple terms (for what I assume is the same collection of
values) becomes confusing to simple-minds (like mine).
The "dict(c)" is unused (and unusable).
Right, now that I've grumped (more than) enough:
Please take a look at the keys and values in
"parts_in_inv_dict"/"inv_dict". What data-type(s) are they - are these
(both) integers, strings, floats, booleans, ...or what?
Similarly, inspect "Belt Counter"/"c"/"belt_dict". What data-types are
used here?
Spotted the difference?
NB in Python: 40885 != '40885'
--
Regards =dn
More information about the Tutor
mailing list