is this pythonic?

TP Tribulations at Paralleles.invalid
Wed Jan 21 16:16:32 CET 2009


Hi,

Is the following code pythonic:

>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}]
>>> dict = [ dict for dict in l if dict['title']=='ti']
>>> l.remove(*dict)
>>> l
[{'title': 'to', 'value': 2}]

Precision: I have stored data in the list of dictionaries l, because in my
application I am sure that "title" is unique for each record. But perhaps
it is better to imagine that someday it will not be anymore the case? And
rather use a data storage as the following?

l = { '001':{"title":"to", "value":2}, '002'
{"title":"ti","value":"coucou"}}

The problem with this storage is that it implies to manipulate some "ids"
that have not any meaning for a humain being (001, 002, etc).

Thanks a lot for you opinion,

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)



More information about the Python-list mailing list