Removing items from a list
Thomas Philips
tkpmep at gmail.com
Mon Feb 13 08:55:41 EST 2012
I could indeed have addressed this problem with a list comprehension.
It escaped me at the time because the larger problem I was trying to
solve included removing data from a dictionary:
months =
sorted(list(dataDict.keys())) #Sort
months in ascending order
for mth in
reversed(months): #Remove
months with inadequate data
if len(dataDict[mth]) < minItems:
months.remove(mth)
del dataDict[mth]
There's more than one way to solve this problem, and, with the benefit
of hindsight, my solution was sloppy, but thanks to the help I
received, I was able to get my code working correctly. Cleaning up is
the next phase!
Thanks, all.
More information about the Python-list
mailing list