[Tutor] Iterate through dictionary values and remove item
Ricardo Araoz
ricaraoz at gmail.com
Fri May 16 15:01:36 CEST 2008
Kent Johnson wrote:
> On Thu, May 15, 2008 at 12:58 PM, GTXY20 <gtxy20 at gmail.com> wrote:
>> I suspect that I need
>> to get a better handle on the difference between items() and iteritems() and
>> what situations would call for them respectively.
>
> items() returns a list, iteritems() returns an iterator. If you don't
> actually need an explicit list, iteritems() saves the cost of creating
> it.
>
>> Having said that, Kent I am not 100 percent sure of what you menat when you
>> mention a two-level dict. Can you give me a very brief example?
>
> Your dict d would look like this:
> d={
> 1: {23A:[a,b,c,d], 24A:[b,c,d]},
> 2: {23A:[a,b], 24A:[a,b,c,d]}
> }
>
Lads...
>>> d={
... 1: {23A:[a,b,c,d], 24A:[b,c,d]},
... 2: {23A:[a,b], 24A:[a,b,c,d]}
... }
File "<input>", line 2
1: {23A:[a,b,c,d], 24A:[b,c,d]},
^
SyntaxError: invalid syntax
>>>
Let's get a proper syntax for our data before attempting to process it.
More information about the Tutor
mailing list