Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76672
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!enother.net!enother.net!gegeweb.org!eternal-september.org!feeder.eternal-september.org!weretis.net!feeder1.news.weretis.net!news.tota-refugium.de!.POSTED!not-for-mail |
|---|---|
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: More Pythonic implementation |
| Date | Wed, 20 Aug 2014 17:52:14 +0200 |
| Organization | A not so newly installed InterNetNews server |
| Lines | 42 |
| Message-ID | <lt2g7j$c3t$1@r01.glglgl.de> (permalink) |
| References | <mailman.13161.1408473590.18130.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | tota-refugium.de 1408550404 27948 eJwNzLcRwEAIAMGW8DzlYPsvQYou2TllQ2sXUxM9PYKd/ZvMqeDvgtvRvEhiuFTDnzAyJMveAMygkOHWoK1PNwem1i8xSjiG/ku+w07qBx+AYh3l (20 Aug 2014 16:00:04 GMT) |
| X-Complaints-To | abuse@news.tota-refugium.de |
| NNTP-Posting-Date | Wed, 20 Aug 2014 16:00:04 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 Hamster/2.1.0.11 |
| X-User-ID | eJwFwYkBgDAIA8CVJCY842CF/UfonV43P0GXU6tNVEjFetDwzzg9MYXjsB0acmr5Y9tU2bwDLRCE |
| In-Reply-To | <mailman.13161.1408473590.18130.python-list@python.org> |
| Cancel-Lock | sha1:dregspDTzsmJaJm5AU+ETkujBSI= |
| X-NNTP-Posting-Host | eJwFwQcBwEAIBDBLjAMeOZThX0ITU2fvgJvDzi7XAsQcSppttz4PAfbjK+SBDiKpu7rhmKByqbetwtC2TNwq5RDq4pvrVyEdX3QPV/1SUR4w |
| Xref | csiph.com comp.lang.python:76672 |
Show key headers only | View raw
Am 19.08.2014 19:09 schrieb Shubham Tomar: > Lets say I have a function poker(hands) that takes a list of hands and > returns the highest ranking hand, and another function hand_rank(hand) > that takes hand and return its rank. As in Poker > http://www.pokerstars.com/poker/games/rules/hand-rankings/. > > Which of the following is better and more Pythonic ? They are different. > def poker(hands): > return max(hands, key=hand_rank) This one determines the hands element with the biggest hand_rank(i) value and returns it, while > def poker(hands): > return max(hand_rank(hands)) returns the hand_rank value, but only if hand_rank() is applicable to lists. Otherwise, it fails. hands = [1, 2, 3, 4, 5] def hand_rank(i): return -i So, max(hands, key=hand_rank) gives 1 because it has the biggest hand_rank(value) of -1 in the range of -5..-1. OTOH, max(hand_rank(hands)) will fail, because there is no list.__neg__(). If there was, it would be the same as max([-1, -2, -3, -4, -5]), so it would be -1 itself.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
More Pythonic implementation Shubham Tomar <tomarshubham24@gmail.com> - 2014-08-19 22:39 +0530 Re: More Pythonic implementation Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2014-08-20 17:52 +0200
csiph-web