Re: Tuple index

2005-02-25 Thread Scott Robinson
On 21 Feb 2005 15:01:05 -0800, "John Machin" <[EMAIL PROTECTED]> wrote: > >Steve M wrote: >> John Machin wrote: >> >> > >> > Steve M wrote: >> >> I'm actually doing this as part of an exercise from a book. What >the >> > program >> >> is supposed to do is be a word guessing game. The program >auto

Re: Tuple index

2005-02-21 Thread John Machin
Steve M wrote: > John Machin wrote: > > > > > Steve M wrote: > >> I'm actually doing this as part of an exercise from a book. What the > > program > >> is supposed to do is be a word guessing game. The program automaticly > >> randomly selects a word from a tuple. > > > > Care to tell us which boo

Re: Tuple index

2005-02-21 Thread Steve M
Steven Bethard wrote: > Steve M wrote: >> I'm actually doing this as part of an exercise from a book. What the >> program is supposed to do is be a word guessing game. The program >> automaticly randomly selects a word from a tuple. You then have the >> oportunity to ask for a hint. I created anot

Re: Tuple index

2005-02-21 Thread Steve M
John Machin wrote: > > Steve M wrote: >> I'm actually doing this as part of an exercise from a book. What the > program >> is supposed to do is be a word guessing game. The program automaticly >> randomly selects a word from a tuple. > > Care to tell us which book is using a tuple for this, but

Re: Tuple index

2005-02-21 Thread Steven Bethard
Steve M wrote: I'm actually doing this as part of an exercise from a book. What the program is supposed to do is be a word guessing game. The program automaticly randomly selects a word from a tuple. You then have the oportunity to ask for a hint. I created another tuple of hints, where the order o

Re: Tuple index

2005-02-21 Thread John Machin
Steve M wrote: > I'm actually doing this as part of an exercise from a book. What the program > is supposed to do is be a word guessing game. The program automaticly > randomly selects a word from a tuple. Care to tell us which book is using a tuple for this, but hasn't got to lists yet? Cheers,

Re: Tuple index

2005-02-21 Thread Steve M
Michael Hartl wrote: > I actually find it strange that tuples don't have an index function, > since finding the index doesn't involve any mutation. Anyone know why > Python doesn't allow a statement like t.index('foo')? > > In any case, you can use the index method of list objects if you > conve

Re: Tuple index

2005-02-21 Thread Steve M
Steven Bethard wrote: > Steve M wrote: >> I guess I explained my problem incorrectly. Let me try again. >> >> tuple = ("fred", "barney", "foo") >> >> I know that foo is an element of tuple, but what I need to know is what >> the index of foo is, tuple[?]. > > Larry Bates's solution is probably

Re: Tuple index

2005-02-21 Thread Steven Bethard
Michael Hartl wrote: I actually find it strange that tuples don't have an index function, since finding the index doesn't involve any mutation. Anyone know why Python doesn't allow a statement like t.index('foo')? Tuples aren't really intended for this kind of use. See: http://www.python.org/doc/

Re: Tuple index

2005-02-21 Thread Steven Bethard
Steve M wrote: I guess I explained my problem incorrectly. Let me try again. tuple = ("fred", "barney", "foo") I know that foo is an element of tuple, but what I need to know is what the index of foo is, tuple[?]. Larry Bates's solution is probably the best way to go here: py> t = ("fred", "barney"

Re: Tuple index

2005-02-21 Thread Michael Hartl
I actually find it strange that tuples don't have an index function, since finding the index doesn't involve any mutation. Anyone know why Python doesn't allow a statement like t.index('foo')? In any case, you can use the index method of list objects if you convert your tuple to a list first: >>

Re: Tuple index

2005-02-21 Thread Steve M
John Machin wrote: > > Steve M wrote: >> Hello, >> >> I'm trying to figure out the index position of a tuple > member. >> I know the member name, but I need to know the members index > position. > > Tuples, like lists, don't have members in the sense that they can be > "named" like t.foo

Re: Tuple index

2005-02-20 Thread John Machin
Steve M wrote: > Hello, > > I'm trying to figure out the index position of a tuple member. > I know the member name, but I need to know the members index position. Tuples, like lists, don't have members in the sense that they can be "named" like t.foo. The only way of referring to them is

Re: Tuple index

2005-02-20 Thread Erik Max Francis
Larry Bates wrote: Tuples don't have all the nice methods that lists have so convert it to a list. tuple=('a','b','c','d') l=list(tuple) now you can do: list.index('c') which returns 2 Remember index returns -1 when nothing is found. No, that's .find in strings that returns -1. .index in lists rai

Re: Tuple index

2005-02-20 Thread Larry Bates
Tuples don't have all the nice methods that lists have so convert it to a list. tuple=('a','b','c','d') l=list(tuple) now you can do: list.index('c') which returns 2 Remember index returns -1 when nothing is found. Larry Bates Steve M wrote: > Hello, > > I'm trying to figure out th