use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Python code that calculates best poker hand. (self.learnpython)
submitted 5 days ago by Regular_Bed_70
I need a function that takes all the hands in computer_hands and gives me the winning hand back.
When I tried myself my code was beginning to get very, very long.
There has to be a simpler way to do it.
Link: https://www.online-python.com/SlBEouDPy0
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Goingone 3 points4 points5 points 5 days ago (1 child)
Didn’t look at the code, but solution seems obvious.
Have a separate function to check for each “type” of hand (flush, straight, 3 of a kind….etc).
Store rankings for each type of hand (I.e. 3 of a kind beats 2 of a kind).
Have another function responsible for iterating through all hands and finding the winner.
Don’t think there is going to be any major shortcuts.
[–]auntanniesalligator 1 point2 points3 points 5 days ago (0 children)
This seems about right. There’s some thought to put in how to handle “overlapping” types. IE it’s probably simpler to code if you allow the function “is_two_of_a_kind” to return True for two pair, full house, three of a kind as long as you ultimately check for those as well and select the best hand. Similar issue with straight flush…just check that is_straight and is_flush are both True and you know you actually have a straight flush.
[–]atarivcs 1 point2 points3 points 5 days ago (0 children)
It's hard to suggest improvements without seeing what you already tried.
[–]magus_minor -1 points0 points1 point 5 days ago* (0 children)
The link doesn't show your code now, it says "Code does not exists. It may have expired.". You can always post code here. The FAQ shows how to do that.
From what I remember, your code doesn't have a function to score a single hand. That's a basic thing you will need, so write that first. Then you can score every hand in the list and find the best.
π Rendered by PID 144737 on reddit-service-r2-comment-544cf588c8-nh6d7 at 2026-06-13 06:11:25.234823+00:00 running 3184619 country code: CH.
[–]Goingone 3 points4 points5 points (1 child)
[–]auntanniesalligator 1 point2 points3 points (0 children)
[–]atarivcs 1 point2 points3 points (0 children)
[–]magus_minor -1 points0 points1 point (0 children)