Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing empty list?
#1
def kasinski(text):
    trigraphs=[]
    distances=[]
    for trigraph in range (len(text)-2):
        newtrigraph= text[trigraph:trigraph+3]
    if newtrigraph in trigraphs:
        distances.append(trigraph-(text.index(newtrigraph)))
    else:
        trigraphs.append(newtrigraph)
        trigraphs.append(trigraph)
        return distances
Can anyone identify why this function is returning "[]"? I am printing with the string "UZRZEGNJENVLISEXRHLYPYEGTESBJHJCSBPTGDYFXXBHEEIFTCCHVRKPNHWXPCTUQTGDJHTBIPRFEMJCNHVTCFSAIIJENREGSALHXHWZWRZXGTTVWGDHTEYXISAGQTCJPRSIAPTUMGZALHXHHSOHPWCZLBRZTCBRGHCDIQIKTOAAEFTOPYEGTENRAIALNRXLPCEPYKGPNGPRQPIAKWXDCBZXGPDNRWXEIFZXGJLVOXAJTUEMBLNLQHGPWVPEQPIAXATYENVYJEUEI"(this string does contain repeated trigraphs)
Reply
#2
Don't double post
Reply
#3
If the way your code is indented is the way it is in your code snippet, you just have to indent the lines after your for loop as shown below. Hope that helps =]

def kasinski(text):
    trigraphs=[]
    distances=[]
    for trigraph in range (len(text)-2):
        newtrigraph= text[trigraph:trigraph+3]
        if newtrigraph in trigraphs:
            distances.append(trigraph-(text.index(newtrigraph)))
        else:
            trigraphs.append(newtrigraph)
            trigraphs.append(trigraph)
        return distances
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Eight Queens Problem, error in printing list snl_9527 10 1,527 Apr-30-2025, 04:22 PM
Last Post: Gribouillis
  what to return for an empty list Skaperen 2 1,362 May-24-2024, 05:17 PM
Last Post: Skaperen
  Code with empty list not executing adeana 9 6,143 Dec-11-2023, 08:27 AM
Last Post: buran
  set.difference of two list gives empty result wardancer84 4 2,737 Jun-14-2022, 01:36 PM
Last Post: wardancer84
Question Printing through list.. again jesse68 2 1,893 Apr-16-2022, 03:24 PM
Last Post: jesse68
  displaying empty list vlearner 5 3,161 Jan-19-2022, 09:12 AM
Last Post: perfringo
  Remove empty keys in a python list python_student 7 6,053 Jan-12-2022, 10:23 PM
Last Post: python_student
  help for list printing jip31 8 5,397 May-01-2021, 03:52 AM
Last Post: Pedroski55
  What is the value after JOINING an empty list? JaneTan 2 7,613 Jan-04-2021, 06:25 PM
Last Post: deanhystad
  Problem printing last element from a list tester_V 3 4,232 Oct-30-2020, 04:54 AM
Last Post: tester_V

Forum Jump:

User Panel Messages

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