443,907 Members | 2,039 Online
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

# What is the the best and easiest way to remove elements from a list?

 P: 3 Hi! I'm working on a solitaire game, with a different card deck. First I create a big list with 81 elements (cards in this case), cardList. From this list, six cards are ramdomly picked and put into another list, playerCardList, and printed on the court. Once the cards are printed the player is asked to remove three cards. I would like these cards to be removed from cardList so they don't appear again. I would also like them to be put into a new list where I can compare them to one another. Expand|Select|Wrap|Line Numbers class Kortlek():     def __init__(self,colors=[], forms=[], numbers=[], grades=[]):         self.cardList = []         self.playerCardList = []         for color in colors:             for form in forms:                 for number in numbers:                     for grade in grades:                         tmp= Kort(color, form, number, grade)                         self.cardList.append(tmp)       def cards(self):         for a in random.sample(self.cardList, 6):             self.playerCardList.append(a)           self.write()           self.question()       def question(self):         val = raw_input("Would you like to remove three cards?\n1.Yes\n2.Quit\n")         if val == "1":             for kort in range(3):                 txt = "Write the number of card " + str(card) + ":\n"                 kortID = int(raw_input(txt))                 try:                     self.playerCardList.pop(kortID-1)                 except IndexError:                     print "That card is not in your pile"                     kortID = int(raw_input(txt))                     self.playerCardList.pop(kortID-1)                 self.addCard()           elif val == "2":             quit()           else:             print "Pick either 1 or 2"           def addCard(self):         for a in random.sample(self.cardList, 3):             self.playerCardList.append(a)           self.write()         self.question()       def write(self):         for b in self.playerCardList:             b.visa()   def cardShuffle():     card = Kortlek(["blue   ", "yellow ", "red    "],["triangel", "circle  ", "square  "],[1, 2, 3],[1, 2, 3])     card.cards()       Thankful for any help! :) Dec 5 '10 #1