[Tutor] add to list
chat_window_char_definition = { 2.7.1. : 1, 2.3.3.3.3. : 2, 2.2.3.3.4. : 3, 2.2.2.7.1. : 4, 4.3.3.3.4. : 5, } how do I automatically add to this list without doing it by hand? Also, the list is of tuples of 2, how ever, I need to have a tuple of 3, is that possible? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] add to list
elis aeris wrote: chat_window_char_definition = { 2.7.1. : 1, 2.3.3.3.3. : 2, 2.2.3.3.4. : 3, 2.2.2.7.1. : 4, 4.3.3.3.4. : 5, } how do I automatically add to this list without doing it by hand? Is there some pattern to the values? I can't see it. Also, the list is of tuples of 2, how ever, I need to have a tuple of 3, is that possible? Tuples can be whatever length you want. But what you have is not a list of tuples, it is a dict mapping keys to values. You could make the keys or the values be tuples of strings rather than strings. Some context would probably help us give you a better answer. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] add to list
there is no pattern in the numbers. but don't worry about it, because all i am doing is this: 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. it's a dictionary. On Sat, Mar 22, 2008 at 2:59 PM, Kent Johnson [EMAIL PROTECTED] wrote: elis aeris wrote: chat_window_char_definition = { 2.7.1. : 1, 2.3.3.3.3. : 2, 2.2.3.3.4. : 3, 2.2.2.7.1. : 4, 4.3.3.3.4. : 5, } how do I automatically add to this list without doing it by hand? Is there some pattern to the values? I can't see it. Also, the list is of tuples of 2, how ever, I need to have a tuple of 3, is that possible? Tuples can be whatever length you want. But what you have is not a list of tuples, it is a dict mapping keys to values. You could make the keys or the values be tuples of strings rather than strings. Some context would probably help us give you a better answer. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] add to list
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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] add to list
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 [EMAIL PROTECTED] 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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor