<div dir="ltr"><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[Chris Angelico]<br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I use decks of cards primarily for non-game<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">usage (for instance, teaching data structures and algorithms - cards<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">laid out on a table can represent a tree, heap, array, etc)</span></blockquote><div><br>I do too. They're a great tool for visualizing and physically trying out different techniques.<br><br><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[Chris Angelico]<br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">A deck containing four suits of thirteen<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">cards plus one joker would have 53 cards, which is a prime number;<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">printing 54 cards lets you lay them out as 9 by 6 on a sheet, so it's<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">easy to add a second joker. Some decks (I have an Alice in Wonderland<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">themed deck) have *four* jokers.</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">As such, the most logical way to do this would be as an attribute of<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">the card.</span></blockquote><div><br>In most cases I've seen wild cards used, it's a declaration about a certain card (e.g. "Eights are wild."<br>or "The 2 of clubs is wild."). I've found that if you're trying to model a game like poker or Monopoly, it's tempting to add complexity to simple objects, but it can lead to problems later on. A card doesn't know if it's wild. That's a function of the game being played. An ace may be high or low.<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 21, 2018 at 2:06 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, Aug 22, 2018 at 4:56 AM, Abe Dillon <<a href="mailto:abedillon@gmail.com">abedillon@gmail.com</a>> wrote:<br>
> [Chris Angelico]<br>
>><br>
>> In English, "card is not wild" can<br>
>> be interpreted as a membership check, but in Python, it is only an<br>
>> identity check; you're capitalizing on false readability by using this<br>
>> notation.<br>
><br>
><br>
> I promise that wasn't my intent. Since both my proposed form and the lambda<br>
> form use the same expression,<br>
> it doesn't really tip the balance in favor of my argument. Also, most toy<br>
> card problems I work with use a finite,<br>
> immutable set of cards, so identity checking isn't *that* weird.<br>
<br>
</span>Fair enough. To be fair, I use decks of cards primarily for non-game<br>
usage (for instance, teaching data structures and algorithms - cards<br>
laid out on a table can represent a tree, heap, array, etc), and my<br>
decks of cards are artistic. A deck containing four suits of thirteen<br>
cards plus one joker would have 53 cards, which is a prime number;<br>
printing 54 cards lets you lay them out as 9 by 6 on a sheet, so it's<br>
easy to add a second joker. Some decks (I have an Alice in Wonderland<br>
themed deck) have *four* jokers.<br>
<br>
As such, the most logical way to do this would be as an attribute of<br>
the card. Its jokerness is as much a feature as the clubness of<br>
another card. You can pick up a physical card, look at it, and say<br>
"This is a joker"; you don't have to see if it's in a list of specific<br>
known jokers.<br>
<br>
hand = sorted(cards, by=value[card.suit] if not card.wild else<br>
max_value with card)<br>
<br>
Honestly, though, it'd usually be more interesting to sort by rank<br>
within suit. What you're doing here would group the cards by suit,<br>
ignoring their ranks; more useful would be:<br>
<br>
hand = sorted(cards, key=lambda card: (card.is_wild, card.suit, card.rank))<br>
<br>
Much cleaner. No conditionals needed.<br>
<div class="HOEnZb"><div class="h5"><br>
ChrisA<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></div></blockquote></div><br></div>