Knowing an item's location in an array [duplicate] Knowing an item's location in an array [duplicate] arrays arrays

Knowing an item's location in an array [duplicate]


Use the index() method on list.

See Finding the index of an item given a list containing it in Python:

>>> ["foo","bar","baz"].index('bar')1


index(arg) returns the index of arg within a list. So you would do:

from random import shuffledeck = [value + suit for value in range(1, 11) + list ("AJQK") for suit in "HCDS"] + ["J1", "J2"]shuffle(deck)idx = deck.index('J1')deck[idx: idx+2] = deck[idx: idx+2].reverse()