If your cards are embedded in an inconvenient way:
>>> Cards = [[["QS","5H","AS"],["2H","8H"],["7C"]],[["9H","5C"],["JH"]],["7D"]] >>> def getCards(cardList,myCards=[]): #change this to myCards, and pass in a list to mutate this is just for demo if isinstance(cardList,list): for subList in cardList: getCards(subList) else: myCards.append(cardList) return myCards >>> getCards(Cards) ['QS', '5H', 'AS', '2H', '8H', '7C', '9H', '5C', 'JH', '7D']
Will recursively go through the list and find all the elements. These are some points that I have performed comparing the performance of the selected flattern method with mine:
>>> print(timeit.timeit(r'getCards([[["QS","5H","AS"],["2H","8H"],["7C"]],[["9H","5C"],["JH"]],["7D"]],[])',setup="from clas import getCards")) 5.24880099297 >>> timeit.timeit(r'flatten([[["QS","5H","AS"],["2H","8H"],["7C"]],[["9H","5C"],["JH"]],["7D"]])',setup="from compiler.ast import flatten") 7.010887145996094