Hi all.
In my application I have chosen as data structure a list of
dictionaries. Each dictionary has just one key and the corresponding
value.
structure = [{'field1': lenght1}, {'field2': lenght2}, ........]
Initially, to obtain the key and the value I used this code,
for structure in record_structure:
field_name = structure.keys()[0]
displacement = structure[field_name]
but after some thoughts I arrived to:
field_name, displacement = structure.items()[0]
which to me seems a lot better.
At this point I don't like much that [0] to access a list that I know
always contains a single element. Can I improve the code with
something better?
Thanks!
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor