[Python-ideas] Does jargon make learning more difficult?

Chris Angelico rosuav at gmail.com
Tue Aug 21 15:06:46 EDT 2018


On Wed, Aug 22, 2018 at 4:56 AM, Abe Dillon <abedillon at gmail.com> wrote:
> [Chris Angelico]
>>
>> In English, "card is not wild" can
>> be interpreted as a membership check, but in Python, it is only an
>> identity check; you're capitalizing on false readability by using this
>> notation.
>
>
> I promise that wasn't my intent. Since both my proposed form and the lambda
> form use the same expression,
> it doesn't really tip the balance in favor of my argument. Also, most toy
> card problems I work with use a finite,
> immutable set of cards, so identity checking isn't *that* weird.

Fair enough. To be fair, I use decks of cards primarily for non-game
usage (for instance, teaching data structures and algorithms - cards
laid out on a table can represent a tree, heap, array, etc), and my
decks of cards are artistic. A deck containing four suits of thirteen
cards plus one joker would have 53 cards, which is a prime number;
printing 54 cards lets you lay them out as 9 by 6 on a sheet, so it's
easy to add a second joker. Some decks (I have an Alice in Wonderland
themed deck) have *four* jokers.

As such, the most logical way to do this would be as an attribute of
the card. Its jokerness is as much a feature as the clubness of
another card. You can pick up a physical card, look at it, and say
"This is a joker"; you don't have to see if it's in a list of specific
known jokers.

hand = sorted(cards, by=value[card.suit] if not card.wild else
max_value with card)

Honestly, though, it'd usually be more interesting to sort by rank
within suit. What you're doing here would group the cards by suit,
ignoring their ranks; more useful would be:

hand = sorted(cards, key=lambda card: (card.is_wild, card.suit, card.rank))

Much cleaner. No conditionals needed.

ChrisA


More information about the Python-ideas mailing list