Apr-14-2019, 10:09 PM
(This post was last modified: Apr-14-2019, 10:09 PM by mrapple2020.)
Goal:
if I see a certain value (example below is "0/1") listed more than 2 or more times I want:
1) Remove all respective items from the defaultdict value list.
I tried the example below from the documentation at python.org. No the example on the bottom would work for 'int'. Since this is a list, I am not sure how to proceed. Help is appreciated.
if I see a certain value (example below is "0/1") listed more than 2 or more times I want:
1) Remove all respective items from the defaultdict value list.
I tried the example below from the documentation at python.org. No the example on the bottom would work for 'int'. Since this is a list, I am not sure how to proceed. Help is appreciated.
>>> >>> l = defaultdict(list) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'defaultdict' is not defined >>> from collections import defaultdict >>> l = defaultdict(list) >>> mylist=["0/1"] >>> l['FAIL'].append(mylist) >>> l defaultdict(<class 'list'>, {'FAIL': [['0/1']]}) >>> mylist=["0/1"] >>> l['FAIL'].append(mylist) >>> l defaultdict(<class 'list'>, {'FAIL': [['0/1'], ['0/1']]}) >>> mylist=["0/2"] >>> l['FAIL'].append(mylist) >>> l defaultdict(<class 'list'>, {'FAIL': [['0/1'], ['0/1'], ['0/2']]}) >>> l.count("0/1") Traceback (most recent call last): File "<stdin>", line 1, in <module> >>> for k in l: ... l[k] += 1 ... Traceback (most recent call last): File "<stdin>", line 2, in <module> TypeError: 'int' object is not iterable #since this is a list, is not working. Any ideas? >>> >>>