Home > Blockchain >  Why is it outputting a blank list?
Why is it outputting a blank list?

Time:02-14

I'm trying to make a wordle helper that shows possible answers, but it doesn't seem to work. It would ask for the first letters, last letters and some letters in between. The codes runs ok, but shows a blank list. I've read it some more but it doesn't seem wrong to me. Here are the codes from middle to end:

List = ["apple", "which", "there", "their", "about"]
firstletterslist = []
lastletterslist = []
finallist = []
for a in List:
    if a.startswith(firstletters) == True:
        firstletterslist.append(a)
for b in firstletterslist:
    if b.endswith(lastletters) == True:
        lastletterslist.append(b)
for c in lastletterslist:
    if knownletters in c:
        finallist.append(c)
print("The words possible are: ")
print(finallist)

The output is:

The words possible are: 
[]

Would have expected "apple" as the output if "a" is firstletters, "e" is lastletters and "p" in knownletters, but blank list is shown. Any help would be appreciated, thanks a lot.

CodePudding user response:

try to double check your code for any typo error. I ran your code with hardcoded inputs for firstletters, lastletters, and knownletters, and it seems to be working fine.

List = ["apple", "which", "there", "their", "about"]
firstletterslist = []
lastletterslist = []
finallist = []
firstletters = 'a'
lastletters = 'e'
knownletters = 'p'
for a in List:
    if a.startswith(firstletters) == True:
        firstletterslist.append(a)
for b in firstletterslist:
    if b.endswith(lastletters) == True:
        lastletterslist.append(b)
for c in lastletterslist:
    if knownletters in c:
        finallist.append(c)
print("The words possible are: ")
print(finallist)

The output i got was: ['apple']

CodePudding user response:

I also can run the code without any problems. Is there maybe a problem/error with the way you input the variables firstletters, lastletters, and knownletters?

  • Related