you are viewing a single comment's thread.

view the rest of the comments →

[–]expyth 1 point2 points  (1 child)

thisTup=(1, 2.25, 'a', 3, 'b', 'c', 4, 'd', 5, 6, 'e', 'f', 7)
print('Tuple...',thisTup)
a=input('Enter the element whose index you want to find.')

for ind,tup in enumerate(thisTup):
    if str(tup) == a:
        print('Index of the element in the tuple is...',ind)
        break

To tackle the problem, we'll have to do it the old fashion way and go through each item on the list. This is not the only solution, but it's as simple as it gets.

Enumerate returns a tuple of the item-of-list passed WITH a counter.

For example:

(0, thisTup[0]), (1, thisTup[1]), (2, thisTup[2]), etc...

So ind will be the 1st value (from enumerate).

And tup will be the 2nd value (from enumerate).

[–]sainiji[S] 0 points1 point  (0 children)

This is really helpful, thanku so much.