[Tutor] add to list
elis aeris
hunter92383 at gmail.com
Sat Mar 22 23:14:55 CET 2008
Another part of program takes care of that patternless stuff, only saving
and retrieving for comparison is concerned for this part of the code.
In [11]: d = { ('a', 'b'): '1',
....: ('c', 'd'): '2' }
In [12]:
In [12]: d['a', 'b']
Out[12]: '1'
that does look like what I looking for, how does it work?
On Sat, Mar 22, 2008 at 3:12 PM, Kent Johnson <kent37 at tds.net> wrote:
> elis aeris wrote:
> > there is no pattern in the numbers.
>
> Then how do you expect to create them automatically? I don't understand
> that part of the question.
>
> > two strings that look like "2.3.3.3.3.", youknow, str(int) + "." +
> > str(int) + "." and so forth
> > are presented and they equal to a value, which is the third string.
> >
> > in short, given the first two strings, return the third string from the
> > list.
>
> That sounds like you want a dict whose key is a tuple of the first two
> strings, and the value is the third string. For example,
> In [11]: d = { ('a', 'b'): '1',
> ....: ('c', 'd'): '2' }
> In [12]:
> In [12]: d['a', 'b']
> Out[12]: '1'
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080322/7f7f417a/attachment.htm
More information about the Tutor
mailing list