[Tutor] python: how do I create a list of definitions?
elis aeris
hunter92383 at gmail.com
Fri Jul 20 00:24:47 CEST 2007
I don't understand dict
On 7/20/07, Eric Brunson <brunson at brunson.com> wrote:
>
> elis aeris wrote:
> > like, I am doing string substitution:
> >
> >
> > if x = 2243:
> > string = string + "e"
> > if x = 2234:
> > string = string + "p"
>
> If I'm following correctly...
>
> How about using a dict:
>
> list = { 1: 'a', 2: 'b', 3: 'c', 2342: 'p', 4234: 'e' }
>
> if x in list:
> string += list[x]
>
> But I'm not sure what that outer loop is good for in your final example,
> so I may not understand what you're asking.
>
> >
> > and so forth.
> >
> >
> > how do I create this:
> >
> >
> > list = [
> > (2342,p)
> > (4234,e)
> > and so forth,
> >
> >
> > ]
> >
> >
> >
> > so I can use it like this:
> >
> > for a in range(10):
> > If x = list[a][0]:
> > string = string + list[a][1]
> >
> >
> > ?
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070720/8054f016/attachment.htm
More information about the Tutor
mailing list