Python: Code is ignoring the if and else
I'm trying to create a game of Go Fish in Python. But I've stumbled onto a
little problem that I can't seem to figure out how to deal with.
There is a human player (player 0) and three computer players (from 1-3). The
human player goes first and chooses a target player. And then a card rank (for
example, the player could target player two and choose jacks, then the computer
would have to give the player all its jacks).
What I have so far is below but the problem I'm having is right at the bottom
of the code. So far, the code generates a deck, creates hands for every player,
and then shows the player his/her cards. Then the player is asked which
computer player he/she wants to target as well as the rank of cards.
The problem I'm having is with the last set of lines (the def player_0_hitman)
at the bottom of the code. Any help would be much appreciated. There are
basically three issues I'm having problems with.
Basically, my code is ignoring the if's and else's. I don't get why.
Everything appears to be positioned correctly, but for some odd reason, even
after an if, the program also runs the else as well.
the "hit" is not being returned. Even though in the definition, I have the
hit set to hit = hit - 1 for the last else, it still reruns the whole
definition again as if it the hit was 1
I'm trying to use the count line to count how many cards are being
transferred so the program will tell the player how many cards he gains when he
gets a successful guess but I only get a statement saying I got 1 card each
time no matter what (whether I get no cards or I get more than one).
I understand the basics of what I need to do but I can't seem to get a working
code for this. I've tried changing the "for" to "if" but I get all sorts of
errors so I don't think that will work. Then I tried converting "hit" into
another code before entering the definition, changing it while inside, then
converting it back before returning it but that also seems to do nothing, and I
still get the same issues.
CODE:
import random
def SetDeck():
suitList = ["s", "c", "d", "h"]
rankList = ["a", "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k"]
deck = []
for suite in range(4):
for rank in range(13):
deck.append(rankList[rank]+suitList[suite])
return deck
def Shuffle(deck):
nCards = len(deck)
for i in range(nCards):
j = random.randint(i,nCards-1)
deck[i], deck[j] = deck[j], deck[i]
return deck
def GetTopCard(shuffledDeck):
return shuffledDeck.pop(0)
def DealInitialCards(nPlayers,nCards,shuffledDeck):
playersCards = [["" for j in range(nCards)] for i in range(nPlayers)]
for j in range(nCards):
for i in range(nPlayers):
playersCards[i][j] = GetTopCard(shuffledDeck)
return playersCards
def Sort(cards):
rankString = "a23456789tjqk"
swapped=True
while swapped:
swapped = False
for i in range(len(cards)-1):
if rankString.find(cards[i][0])>rankString.find(cards[i+1][0]):
cards[i],cards[i+1]=cards[i+1],cards[i]
swapped = True
return
def ShowCards(player,cards):
print("\n")
print("Player "+str(player)+" has**")
print("\n")
for i in range(len(cards)):
print(cards[i]),
print("\n")
return
def ShowMessage(msg):
print("")
print(str(msg))
print("\n")
return
def remove_suits(player):
new_hand = []
for card in pHands[player]:
new_card = card[0]
new_hand.append(new_card)
return new_hand
def choosing_target():
target_player = raw_input ("Who do you want to ask? (1-3)")
while target_player.isdigit() == False or 1 > int(target_player) or 3 <
int(target_player):
print "Error: Must type a valid player id (from 1 to 3)"
target_player = raw_input ("Who do you want to ask? (1-3)")
target_player = int(target_player)
return target_player
def target_rank():
target_card = raw_input ("What rank are you seeking? (" +
str(",".join(new_hand)) + ")")
while target_card not in new_hand:
print "Error: Must type one of the follow valid single character card
ranks"
print str(",".join(new_hand))
target_card = raw_input ("What rank are you seeking? (" +
str(",".join(new_hand)) + ")")
return target_card
print("~"*70)
print("~"*25+"WELCOME TO GO FISH!"+"~"*26)
print("~"*70)
nPlayers = 4
nCards = 10
deck = SetDeck()
sDeck = Shuffle(deck[:])
pHands = DealInitialCards(nPlayers,nCards,sDeck)
Sort(pHands[0])
ShowCards(0,pHands[0])
hit = 1
while hit == 1 :
ShowMessage("TURN: Player 0, its your turn.")
target_player = choosing_target()
new_hand = remove_suits(0)
Re: Python: Code is ignoring the if and else
On Friday, August 2, 2013 6:39:43 PM UTC-7, John Ladasky wrote: > On Friday, August 2, 2013 5:40:52 PM UTC-7, [email protected] wrote: > > > Basically, my code is ignoring the if's and else's. I don't get why. > > > Everything appears to be positioned correctly, but for some odd reason, even > > > after an if, the program also runs the else as well. > > > > Look carefully at your indentation. One "else" statement is at the same > indentation as a "for" statement rather than an "if" statement. So what, you > say? > > > > http://docs.python.org/2/tutorial/controlflow.html > > > > "Loop statements may have an else clause; it is executed when the loop > terminates through exhaustion of the list (with for) or when the condition > becomes false (with while), but not when the loop is terminated by a break > statement." > > > > I don't know of any other computer programming language besides Python which > has the "for...break...else" idiom. However, I know quite a few that do not. > I find it useful in many situations. Yeah, I already know about that. But if I try to change it, I'm not even able to start the program. If I try to change the if statement that it corresponds with, I get a an error saying "card" is not a global. And if I try to shift it in, for some reason...the program runs through the MISS line multiple times. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Code is ignoring the if and else
On Friday, August 2, 2013 6:42:30 PM UTC-7, Terry Reedy wrote: > Nonsense: they are executed just as you ask, even though what you ask is > > not what you meant. > > > > On 8/2/2013 8:40 PM, [email protected] wrote: > > > > > def player_0_hitman(hit): > > > for card in pHands[target_player]: > > > if target_card[0] == card[0]: > > > count = pHands[target_player].count(card) > > > pHands[0].append(card) > > > pHands[target_player].remove(card) > > > ShowMessage("HIT: " + str(count) + " card(s) transferred") > > > else: > > else: # indent to match if > > > if target_card[0] != card[0]: > > # delete this if line, see below. > > > > > top_card = GetTopCard(sDeck) > > > pHands[0].append(top_card) > > > if top_card[0] == target_card[0]: > > > ShowMessage("HIT: LUCKILY Player 0 has fished up a rank <" > > + str(top_card[0]) + ">!!!") > > > else: > > > ShowMessage("MISS: You fished up the rank <" + > > str(top_card[0]) + ">") > > > hit = hit - 1 > > > return hit > > > > This executes the for loop multiple times and the the else: clause of > > the *for* statement (see the ref manual). I believe you want the whole > > else: clause indented so that it will be executed when the if condition > > is false. If so, the second if is redundant and should just be removed. > > Yeah, thanks for the advice. But unfortunately, I already tried that and I > ended up with a whole bunch of new errors. > > -- > > Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Code is ignoring the if and else
On Friday, August 2, 2013 7:11:37 PM UTC-7, Joshua Landau wrote:
> On 3 August 2013 02:44, wrote:
>
>
>
> Yeah, I already know about that. But if I try to change it, I'm not even able
> to start the program. If I try to change the if statement that it corresponds
> with, I get a an error saying "card" is not a global. And if I try to shift
> it in, for some reason...the program runs through the MISS line multiple
> times.
>
>
>
>
>
> You have a car with a broken engine and a broken tire and are telling us that
> you refuse to fix the engine because it highlights the problem of the broken
> tire.
>
>
> Take the fix and move on to the next problem.
>
>
>
>
> One piece of advice is about scoping. This is perhaps the hardest "gotcha" of
> Python conceptually, but it's sensible once you understand the justifications.
>
>
> Run the four commands below and try and understand why this applies to your
> code.
>
>
>
>
> a = 1
>
>
> def access_global():
> print(a)
>
>
> def set_variable():
> a = 2
> print(a)
>
>
> def broken_set():
>
>
> a = a + 1
> print(a)
>
>
> def also_broken():
> print(a)
> return
> a = 1 # Never run!
>
>
> The fix for the broken variants is to start the functions with "global a".
I'll take a look at those. I used that fix you brought up as well but the main
issue I get after that is:
I'll try to explain the main issue I'm having as accurately as possible.
Basically, I've changed the indentations around but the main issue I get is
that the GetTopCard(sDeck) line is being run multiple times for some reason. So
when I run the program, I get "MISS: You fished up the rank.." multiple
times and my list pHands[0] is increased by several number combinations when I
only want it to increase by one. I also updated that last definition in my main
code.
def player_0_hitman(hit):
for card in pHands[target_player]:
if target_card[0] == card[0]:
count = pHands[target_player].count(card)
pHands[0].append(card)
pHands[target_player].remove(card)
ShowMessage("HIT: " + str(count) + " card(s) transferred")
else:
top_card = GetTopCard(sDeck)
pHands[0].append(top_card)
if top_card[0] == target_card[0]:
ShowMessage("HIT: LUCKILY Player 0 has fished up a rank <" +
str(top_card[0]) + ">!!!")
else:
ShowMessage("MISS: You fished up the rank <" + str(top_card[0])
+ ">")
hit = hit - 1
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python: Code is ignoring the if and else
On Friday, August 2, 2013 10:04:56 PM UTC-7, Terry Reedy wrote: > On 8/2/2013 10:24 PM, [email protected] wrote: > > > > Looking at this again, I believe you actually had the structure almost > > right before. You want to look through *all* of the target players cards > > and if *none* of them match, (ie the search fails), you want to draw 1 > > card. What you were missing before is break or return > > > > def player_0_hitman(hit): > > for card in pHands[target_player]: > > if target_card[0] == card[0]: > > count = pHands[target_player].count(card) > > pHands[0].append(card) > > pHands[target_player].remove(card) > > ShowMessage("HIT: " + str(count) + " card(s) transferred") > > return True > > > ># else: needed if just break above, but not with return > > > >top_card = GetTopCard(sDeck) > >pHands[0].append(top_card) > >if top_card[0] == target_card[0]: > >ShowMessage("HIT: LUCKILY Player 0 has fished up a rank <" + > > str(top_card[0]) + ">!!!") > >return True > > else: > > ShowMessage("MISS: You fished up the rank <" + > > str(top_card[0]) + ">") > > hit = hit - 1 > > return False > > > > The returns are based on what I remember of the rules from decades ago, > > that a hit either in the hand or the draw allowed another turn by the > > player. > > > > -- > > Terry Jan Reedy Thank you, that information worked quite well and is much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Removing matching items from a list?
Basically, I'm trying to find out how to remove matching items from a list. But there doesn't seem to be any information on how to go about doing this specific function. For example, what I want is: let's say there is a list: pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd'] So up there, my list, which is named pHands[0] has ten items in it. I'm trying to make a function where a search is initiated into the list and any matching items with a first matching number/letter reaching four are removed So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from the list. I need the list to automatically detect if there are four matching first letter/numbers in the items in the list. The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 1:12:55 PM UTC-7, [email protected] wrote: > Basically, I'm trying to find out how to remove matching items from a list. > But there doesn't seem to be any information on how to go about doing this > specific function. > > > > For example, what I want is: > > > > let's say there is a list: > > > > pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd'] > > > > So up there, my list, which is named pHands[0] has ten items in it. > > > > I'm trying to make a function where a search is initiated into the list and > any matching items with a first matching number/letter reaching four are > removed > > > > So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from > the list. I need the list to automatically detect if there are four matching > first letter/numbers in the items in the list. > > > > The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd'] Ah, I forgot to mention. This function will be used for other lists to so it can't specifically target "a" and needs to auto search for four matching first letters. If it helps, the two letters/numbers in each item are strung together by the following function: for suite in range(4): for rank in range(13): deck.append(rankList[rank]+suitList[suite]) So they can be directly accessed using: card[0] for the first letter/number card[1] for the second -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 3:37:41 PM UTC-7, Steven D'Aprano wrote:
> On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:
>
>
>
> > Basically, I'm trying to find out how to remove matching items from a
>
> > list. But there doesn't seem to be any information on how to go about
>
> > doing this specific function.
>
>
>
> The documentation cannot possibly cover every single one of the infinite
>
> number of things somebody might want to do with Python. Programming is
>
> about figuring out how to do the things you want from the tools provided
>
> by the language.
>
>
>
>
>
> > For example, what I want is:
>
> >
>
> > let's say there is a list:
>
> >
>
> > pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
>
> >
>
> > So up there, my list, which is named pHands[0] has ten items in it.
>
>
>
> Ten items? I wouldn't have known that if you didn't say so! *wink*
>
>
>
> But seriously... you don't need to repeat obvious things like that. We
>
> can count as well as you can.
>
>
>
> But more importantly, it is irrelevant. Is "ten items" important to this
>
> problem? No. What if there were nine, or thirty five, or seven? Would the
>
> problem of "removing matching items" change? No, the problem remains the
>
> same regardless of how many items there are.
>
>
>
>
>
> > I'm trying to make a function where a search is initiated into the list
>
> > and any matching items with a first matching number/letter reaching four
>
> > are removed
>
>
>
> In general, rather than removing items from a list, it is faster and
>
> safer (less error-prone) to create a new list with the items not removed.
>
> But either way, when trying to program, start by thinking about how *you*
>
> would do this task by hand:
>
>
>
> 1) I would start by counting how many items start with each initial
>
> letter: in your example I would count those starting with 'a' (4),
>
> '7' (1), and so on.
>
>
>
> 2) Then go through those initial letters, and pick out the ones equal to
>
> 4 (or should that be "four or more"?). In this case, only 'a' is 4 or
>
> more, but there could be multiple examples, say, 4 'a's and 6 'b's.
>
>
>
> 3) Then, either delete those items from the original list, *or* make a
>
> new list with the remaining items. Making a new list is usually better.
>
>
>
> Now start turning each step into Python code.
>
>
>
> Step 1:
>
>
>
> Iterate over each item, grab the first character of that item, and add
>
> one to a counter.
>
>
>
> counts = {} # Start with an empty dict.
>
> for item in pHands[0]:
>
> c = item[0] # Grab the first character.
>
> if c in counts:
>
> counts[c] += 1
>
> else:
>
> counts[c] = 1
>
>
>
>
>
> This sets the counter to 1 the first time each character is seen,
>
> otherwise increments the counter by 1. There's a ready-made tool for
>
> doing that:
>
>
>
> from collections import Counter
>
> counts = Counter(item[0] for item in pHands[0])
>
>
>
> but under the hood, it's essentially doing the same thing as I wrote
>
> above.
>
>
>
>
>
> Steps 2 and 3 can be done together:
>
>
>
> new_list = []
>
> for item in pHand[0]:
>
> c = item[0]
>
> # Look up the character in the counter.
>
> if counts[c] < 4:
>
> new_list.append(item)
>
>
>
> pHand[0] = new_list
>
>
>
>
>
>
>
> --
>
> Steven
Ah, all of the replies were useful but I found yours the most useful because of
all the descriptions and in depth steps so I could actually understand what the
code did. Thank you.
Would you also happen to know how to fit in a simple count for each set of
cards that is removed?
For example, 4a's gone would set the count to 1 but if there was also 4j's, the
count would be at 2.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 3:37:41 PM UTC-7, Steven D'Aprano wrote:
> On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:
>
>
>
> > Basically, I'm trying to find out how to remove matching items from a
>
> > list. But there doesn't seem to be any information on how to go about
>
> > doing this specific function.
>
>
>
> The documentation cannot possibly cover every single one of the infinite
>
> number of things somebody might want to do with Python. Programming is
>
> about figuring out how to do the things you want from the tools provided
>
> by the language.
>
>
>
>
>
> > For example, what I want is:
>
> >
>
> > let's say there is a list:
>
> >
>
> > pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
>
> >
>
> > So up there, my list, which is named pHands[0] has ten items in it.
>
>
>
> Ten items? I wouldn't have known that if you didn't say so! *wink*
>
>
>
> But seriously... you don't need to repeat obvious things like that. We
>
> can count as well as you can.
>
>
>
> But more importantly, it is irrelevant. Is "ten items" important to this
>
> problem? No. What if there were nine, or thirty five, or seven? Would the
>
> problem of "removing matching items" change? No, the problem remains the
>
> same regardless of how many items there are.
>
>
>
>
>
> > I'm trying to make a function where a search is initiated into the list
>
> > and any matching items with a first matching number/letter reaching four
>
> > are removed
>
>
>
> In general, rather than removing items from a list, it is faster and
>
> safer (less error-prone) to create a new list with the items not removed.
>
> But either way, when trying to program, start by thinking about how *you*
>
> would do this task by hand:
>
>
>
> 1) I would start by counting how many items start with each initial
>
> letter: in your example I would count those starting with 'a' (4),
>
> '7' (1), and so on.
>
>
>
> 2) Then go through those initial letters, and pick out the ones equal to
>
> 4 (or should that be "four or more"?). In this case, only 'a' is 4 or
>
> more, but there could be multiple examples, say, 4 'a's and 6 'b's.
>
>
>
> 3) Then, either delete those items from the original list, *or* make a
>
> new list with the remaining items. Making a new list is usually better.
>
>
>
> Now start turning each step into Python code.
>
>
>
> Step 1:
>
>
>
> Iterate over each item, grab the first character of that item, and add
>
> one to a counter.
>
>
>
> counts = {} # Start with an empty dict.
>
> for item in pHands[0]:
>
> c = item[0] # Grab the first character.
>
> if c in counts:
>
> counts[c] += 1
>
> else:
>
> counts[c] = 1
>
>
>
>
>
> This sets the counter to 1 the first time each character is seen,
>
> otherwise increments the counter by 1. There's a ready-made tool for
>
> doing that:
>
>
>
> from collections import Counter
>
> counts = Counter(item[0] for item in pHands[0])
>
>
>
> but under the hood, it's essentially doing the same thing as I wrote
>
> above.
>
>
>
>
>
> Steps 2 and 3 can be done together:
>
>
>
> new_list = []
>
> for item in pHand[0]:
>
> c = item[0]
>
> # Look up the character in the counter.
>
> if counts[c] < 4:
>
> new_list.append(item)
>
>
>
> pHand[0] = new_list
>
>
>
>
>
>
>
> --
>
> Steven
Thank you. I found all the replies useful but yours the most useful because of
the descriptions and indepth steps so I could understand what the code did.
Would you also happen to know how I could go about setting up a list that keeps
track of the removed sets?
For example, if there were 4 a's removed, that would be one set. And the list
would be:
['a']
but if there was also 4j's in addition to the a's. It would be:
['a', 'j']
And so forth
--
http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 3:37:41 PM UTC-7, Steven D'Aprano wrote:
> On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:
>
>
>
> > Basically, I'm trying to find out how to remove matching items from a
>
> > list. But there doesn't seem to be any information on how to go about
>
> > doing this specific function.
>
>
>
> The documentation cannot possibly cover every single one of the infinite
>
> number of things somebody might want to do with Python. Programming is
>
> about figuring out how to do the things you want from the tools provided
>
> by the language.
>
>
>
>
>
> > For example, what I want is:
>
> >
>
> > let's say there is a list:
>
> >
>
> > pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
>
> >
>
> > So up there, my list, which is named pHands[0] has ten items in it.
>
>
>
> Ten items? I wouldn't have known that if you didn't say so! *wink*
>
>
>
> But seriously... you don't need to repeat obvious things like that. We
>
> can count as well as you can.
>
>
>
> But more importantly, it is irrelevant. Is "ten items" important to this
>
> problem? No. What if there were nine, or thirty five, or seven? Would the
>
> problem of "removing matching items" change? No, the problem remains the
>
> same regardless of how many items there are.
>
>
>
>
>
> > I'm trying to make a function where a search is initiated into the list
>
> > and any matching items with a first matching number/letter reaching four
>
> > are removed
>
>
>
> In general, rather than removing items from a list, it is faster and
>
> safer (less error-prone) to create a new list with the items not removed.
>
> But either way, when trying to program, start by thinking about how *you*
>
> would do this task by hand:
>
>
>
> 1) I would start by counting how many items start with each initial
>
> letter: in your example I would count those starting with 'a' (4),
>
> '7' (1), and so on.
>
>
>
> 2) Then go through those initial letters, and pick out the ones equal to
>
> 4 (or should that be "four or more"?). In this case, only 'a' is 4 or
>
> more, but there could be multiple examples, say, 4 'a's and 6 'b's.
>
>
>
> 3) Then, either delete those items from the original list, *or* make a
>
> new list with the remaining items. Making a new list is usually better.
>
>
>
> Now start turning each step into Python code.
>
>
>
> Step 1:
>
>
>
> Iterate over each item, grab the first character of that item, and add
>
> one to a counter.
>
>
>
> counts = {} # Start with an empty dict.
>
> for item in pHands[0]:
>
> c = item[0] # Grab the first character.
>
> if c in counts:
>
> counts[c] += 1
>
> else:
>
> counts[c] = 1
>
>
>
>
>
> This sets the counter to 1 the first time each character is seen,
>
> otherwise increments the counter by 1. There's a ready-made tool for
>
> doing that:
>
>
>
> from collections import Counter
>
> counts = Counter(item[0] for item in pHands[0])
>
>
>
> but under the hood, it's essentially doing the same thing as I wrote
>
> above.
>
>
>
>
>
> Steps 2 and 3 can be done together:
>
>
>
> new_list = []
>
> for item in pHand[0]:
>
> c = item[0]
>
> # Look up the character in the counter.
>
> if counts[c] < 4:
>
> new_list.append(item)
>
>
>
> pHand[0] = new_list
>
>
>
>
>
>
>
> --
>
> Steven
Thank you for the advice. It was really helpful with the descriptions and steps.
Would you also happen to know how I could set up a list that keeps track of the
removed sets?
Let's say there's 4 a's taken out. The list would show:
['a']
But if there was also 4 j's in addition to the 4 a's, it would go:
['a', 'j']
and so forth.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 1:12:55 PM UTC-7, [email protected] wrote: > Basically, I'm trying to find out how to remove matching items from a list. > But there doesn't seem to be any information on how to go about doing this > specific function. > > > > For example, what I want is: > > > > let's say there is a list: > > > > pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd'] > > > > So up there, my list, which is named pHands[0] has ten items in it. > > > > I'm trying to make a function where a search is initiated into the list and > any matching items with a first matching number/letter reaching four are > removed > > > > So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from > the list. I need the list to automatically detect if there are four matching > first letter/numbers in the items in the list. > > > > The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd'] Thank you for the advice. It was really helpful with the descriptions and steps. Would you also happen to know how I could set up a list that keeps track of the removed sets? Let's say there's 4 a's taken out. The list would show: ['a'] But if there was also 4 j's in addition to the 4 a's, it would go: ['a', 'j'] and so forth. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 5:25:16 PM UTC-7, Steven D'Aprano wrote: > On Sat, 03 Aug 2013 19:06:05 -0400, Roy Smith wrote: > > > > > In article <[email protected]>, > > > Steven D'Aprano wrote: > > > > > >> 2) Then go through those initial letters, and pick out the ones equal > > >> to 4 (or should that be "four or more"?). > > > > > > Assuming my earlier hunch is correct about these being cards in a deck, > > > and the a's being aces, I would hope it's not "four or more". See my > > > earlier comment about saloons and gunshot wounds. > > > > There are card games that involve more than four suits, or more than one > > pack. In principle, if you draw ten cards from an unknown number of > > packs, you could draw ten Aces, or even ten Aces of the same suit. Think > > of playing blackjack with ten packs shuffled together. > > > > Cripple Mr Onion, for example, uses hands of ten cards drawn from eight > > suits: > > > > http://discworld.wikia.com/wiki/Cripple_Mr_Onion > > > > (yes, it's a real game, based on a fictional game) > > > > > > The Indian Ganjifa deck uses ten "houses" (decks) of 12 cards each. > > > > Pinochle uses the standard four Western suits, but uses two copies of > > each card 9, 10, J, Q, K, A, for 48 cards in total. Sometimes people > > combine two pinochle decks for larger games, so with a double deck all > > ten cards could be Aces. > > > > In the 1930s, there was a fad for playing Bridge with a fifth suit, > > coloured green, called Royals, Leaves, Eagles or Rooks depending on the > > manufacturer. > > > > There are five- and six-suit versions of poker, with at least two still > > commercially available: the five-suit Stardeck pack (which adds Stars), > > and the six-suit Empire deck (which adds red Crowns and black Anchors). > > > > There is an eight-suit Euchre pack that adds red Moons, black Stars, red > > four-leaf Clovers and black Tears to the standard deck. > > > > > > > > -- > > Steven Thank you for the advice. It was really helpful with the descriptions and steps. Would you also happen to know how I could set up a list that keeps track of the removed sets? Let's say there's 4 a's taken out. The list would show: ['a'] But if there was also 4 j's in addition to the 4 a's, it would go: ['a', 'j'] and so forth. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
Thank you, Steven, for the advice. It was really helpful with the descriptions and steps. Would you also happen to know how I could set up a list that keeps track of the removed sets? Let's say there's 4 a's taken out. The list would show: ['a'] But if there was also 4 j's in addition to the 4 a's, it would go: ['a', 'j'] and so forth. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
I have no idea why but I'm unable to post in my original thread so I made a new one here. Thank you for the advice, everyone, especially Steven. It was really helpful with the descriptions and steps. Would you also happen to know how I could set up a list that keeps track of the removed sets? Let's say there's 4 a's taken out. The list would show: ['a'] But if there was also 4 j's in addition to the 4 a's, it would go: ['a', 'j'] and so forth. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing matching items from a list?
On Saturday, August 3, 2013 5:36:42 PM UTC-7, [email protected] wrote: > I have no idea why but I'm unable to post in my original thread so I made a > new one here. > > > > > > Thank you for the advice, everyone, especially Steven. It was really helpful > with the descriptions and steps. > > > > Would you also happen to know how I could set up a list that keeps track of > the removed sets? > > > > Let's say there's 4 a's taken out. The list would show: > > > > ['a'] > > > > But if there was also 4 j's in addition to the 4 a's, it would go: > > > > ['a', 'j'] > > > > and so forth. Sorry for the repeated messages. I have no idea why I have such a long time delay. My messages didn't appear until just now after a few minutes (thought I was having some issues). -- http://mail.python.org/mailman/listinfo/python-list
