[Tutor] python: how do I create a list of definitions?
Eric Brunson
brunson at brunson.com
Fri Jul 20 00:22:17 CEST 2007
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
>
More information about the Tutor
mailing list