Apr-15-2019, 07:34 AM
First of all - which Python version you are using? Python 3 is strongly recommended as support for Python 2 will end this year.
If you are using Python 3 then refer to correct documentation: defaultdict
Your code is not same as in documentation, therefore you dont 'follow' it. But your problem is:
If you are using Python 3 then refer to correct documentation: defaultdict
Your code is not same as in documentation, therefore you dont 'follow' it. But your problem is:
In [1]: from collections import defaultdict In [2]: l = defaultdict(list) In [3]: mylist=["0/1"] In [4]: l['FAIL'].append(mylist) In [5]: l Out[5]: defaultdict(list, {'FAIL': [['0/1']]}) In [6]: l['FAIL'].append(mylist) In [7]: l Out[7]: defaultdict(list, {'FAIL': [['0/1'], ['0/1']]}) In [8]: l['FAIL'].append(["0/2"]) In [9]: l Out[9]: defaultdict(list, {'FAIL': [['0/1'], ['0/1'], ['0/2']]}) In [10]: l['FAIL'].count('0/1') Out[10]: 0 # values are lists therefore count is zero In [11]: l['FAIL'].count(['0/1']) Out[11]: 2 # counting lists gives correct answerValues are under key 'FAIL' and they are not strings but lists. So, in order to count you must give key and then count lists, not strings.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.