[Tutor] Lists with just an item

2005-11-21 Thread Negroup -
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_st

Re: [Tutor] Lists with just an item

2005-11-21 Thread Brian van den Broek
Negroup - said unto the world upon 2005-11-21 03:26: > 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 obtai

Re: [Tutor] Lists with just an item

2005-11-21 Thread Pujo Aji
Hi,       mydic = {'one': 1, 'two': 2}        # to access key:    for x in mydic.keys():    print x        # to access value --> use key    print mydic['one']   Cheers, pujo On 11/21/05, Negroup - <[EMAIL PROTECTED]> wrote: Hi all.In my application I have chosen as data structure a list ofd

Re: [Tutor] Lists with just an item

2005-11-21 Thread Alan Gauld
> Each dictionary has just one key and the corresponding > value. > > structure = [{'field1': lenght1}, {'field2': lenght2}, ] I'd use a tuple rather than a dictionary here: structure = [('field1', lenght1), ('field2', lenght2), ] > but after some thoughts I arrived to: > field_n

Re: [Tutor] Lists with just an item

2005-11-21 Thread Negroup -
2005/11/21, Brian van den Broek <[EMAIL PROTECTED]>: > Hi Negroup, > > why not just make structure a dict: > > structure = {'field1': lenght1, 'field2': lenght2} > > What does having a list of dicts all with a single key add but a layer > of referencing when you want to access? > > If you are tryi

Re: [Tutor] Lists with just an item

2005-11-21 Thread Negroup -
2005/11/21, Alan Gauld <[EMAIL PROTECTED]>: > > Each dictionary has just one key and the corresponding > > value. > > > > structure = [{'field1': lenght1}, {'field2': lenght2}, ] > > I'd use a tuple rather than a dictionary here: Of course, this makes a lot of sense. [cut] > you can now

Re: [Tutor] Lists with just an item

2005-11-21 Thread Hugo González Monteverde
> Probably due to the lacking of experience, but each time I code a > datastructure I am never satisfied, and I have the feeling that I'm > not on the right way.. The same thing happens to me. I actually have a very similar problem to yours now, and I'm rather considering a list of two-element t