Python Forum
trying to put a a filter on identifying a straight
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to put a a filter on identifying a straight
#1
I have written this code to identify possible straights in a serie of numbers. It works find thanks to the help of the people in this forum, but now I want this function to only identify possible straights with 3 items in the set.

flop = [7, 8, 9]
possiblestraight = []

def check3outof3straightinflop(flop, possiblestraightcheck, possiblenumberofstraight, possiblestraight, possiblestraightgradelist):
    possiblestraightgrade = []
    possibleplayershand = []

    for n in range(len(flop)):
        possibleplayershand.append(int(flop[n][0]))

    possibleplayershand.sort()
    
    if possibleplayershand[0] == 1:
        possibleplayershand.append(14)
   
    cardsset = set(possibleplayershand)

    for f in cardsset:
        possiblestraightset = cardsset.intersection(range(f,f+5))
        possiblestraightlist = list(possiblestraightset)
        possiblestraightlist.sort()
        if len(possiblestraightlist) > 2:
            possiblestraight.append(possiblestraightlist)
            
    print(possiblestraight)

#The if statement above here is where the [8,9] is supposed to be removed 

    possiblestraightset =  []
    for s in possiblestraight:
        possiblestraightset.append(set(s))

    possiblestraight = []
    for s in possiblestraightset:
        for r in possiblestraight:
            if s.issubset(r):
                break
        else:
            possiblestraight.append(s)
        
    for n in possiblestraight:
        if n != 0:
            possiblestraightgrade = max(n)
            possiblestraightgradelist.append(possiblestraightgrade)
    possiblestraightgradeset = set(possiblestraightgradelist)

    if possiblestraight != []:
        possiblestraightcheck = True

    possiblenumberofstraight = len(possiblestraight)
    
    return(possiblestraightcheck, possiblestraight, possiblestraightgradeset, possiblenumberofstraight)
Output:
(True, [{8, 9}, {8, 9, 7}], {9}, 2)
So if the flop = [7, 8, 9], i want my funtion to return the list "possiblestraight" as [{8,9,7}] because the set [8,9] is not 3 items long so it should be removed, but the problem is that it's not "possiblestraight = [{8, 9}, {8, 9, 7}]"

Now I 've written this to check if my logic was okay

possiblestraight = []
possiblestraightset = []
possiblestraightlist = []
possibleplayershand = [7, 8, 9]


cardsset = set(possibleplayershand)
for f in cardsset:
    possiblestraightset = cardsset.intersection(range(f,f+5))
    possiblestraightlist = list(possiblestraightset)
    possiblestraightlist.sort()
    if len(possiblestraightlist) > 2:
        possiblestraight.append(possiblestraightlist)
            
print(possiblestraight)
Output:
[[7, 8, 9]]
and it works, my result is [[7, 8, 9]]
So what's the problem?
I have been trying to find the solution for a week now and i can't find it, please help me.
Reply
#2
Found the problem, the element with less than 3 items came from a previous function call, so the list wasn't empty when it was call in this function... sorry
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Identifying if the program I have is python and then decompiling jpnyc 7 2,310 Jun-02-2022, 10:16 PM
Last Post: jpnyc
  Identifying keywords in text drchips 6 92,109 Mar-29-2022, 12:32 PM
Last Post: snippsat
  Identifying string success flag graham23s 4 3,103 Aug-14-2019, 09:27 PM
Last Post: graham23s
  identifying a dictionary with an attribute? Skaperen 7 3,770 Oct-04-2018, 05:48 AM
Last Post: Skaperen
  Identifying only specific words in a string GilbyScarChest 2 2,697 Aug-08-2018, 03:22 AM
Last Post: GilbyScarChest
  Identifying the value of all adjacent elements in an array JoeB 2 8,622 Nov-23-2017, 05:10 PM
Last Post: JoeB
  Identifying object types microphone_head 5 4,435 Oct-01-2017, 02:04 PM
Last Post: buran
  Game not letting player 1 win straight away mzmingle 6 4,124 Aug-16-2017, 04:18 PM
Last Post: mzmingle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020