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
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
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
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
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
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,
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
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
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/
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"
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:
>>
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
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
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
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
15 matches
Mail list logo