0

My python code:

possible1=["which","there","their","about","would","these","other","words","could","write",
"first","water","after","where","right","think","three","years","place","sound","great",
"again","still","every","small","found","those","never","under","might","while","house",
"world","below","asked","going","large","until","along"]

def DeleteNotPossiblePattern(guess,possibilities,pattern):
    for i in range(len(pattern)):
        print(f'Pattern: {pattern[i]} Letter: {guess[i]}')                    
        if pattern[i]=="G":
            print("The option: G")
            for j in possibilities:
                if guess[i]!=j[i]:
                    print(f'In word {j} the letter on {i+1} position is not equal')
                    try:
                        possibilities.remove(j)
                    except ValueError:
                        pass
    return possibilities
k=DeleteNotPossiblePattern("tares",possible1,"GWWWW")

In code it's supposed to return list of words, which will have letter "t" as start and remove all other words from the list, however, it gives wrong results. I can't see where I am making the mistake.

  • You're mentioning `j[i+1]` in the print, but the comparison you're performing is for `j[i]`. Is this intended? `if guess[i]!=j[i]: print(f'In word {j} the letter on {i+1} position is not equal')` – TheBiggerFish Feb 25 '22 at 15:31
  • Yeah, it was intended to move from "programming" into real word numering as the j[0] would be first position. I get what I did wrong here, it's deleting an item and the list is being numered in different way, but I have trouble with moving to another list. – Michał Mazur Feb 25 '22 at 15:36
  • you should create a `copy` of the list `possibilities` (`possibilities.copy()`), iterate thorugh original `possibilities`, and remove from the `copy`. Finally, return the `copy`. – Oliver Mohr Bonometti Feb 25 '22 at 15:36
  • What's the purpose of pattern if we only execute when the pattern char is G (seems like pointless complexity)? – anonymousCoder Feb 25 '22 at 15:39
  • It also patterns Y and W, however I want to fix this issue first, after solving issue with list numeration I will apply it too (it's already done, but with this issue) – Michał Mazur Feb 25 '22 at 15:40
  • @OliverMohrBonometti It fixed my issue, now it works, thanks! – Michał Mazur Feb 25 '22 at 15:42

0 Answers0