Python Forum
Can anyone spot why this function is returning an empty list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can anyone spot why this function is returning an empty list?
#1
def affine_n_encode(text, n, a,b):
    ngraphs=[]
    nums=[]
    texts=[]
    if len(text) % n==0:
        for i in range(len(text)):
            ngraphs.append(text[i:i+n])
        else:
            list(text)
            text.append(['x']*(len(text)%n))
            ''.join(text)
            ngraphs.append(text[i:i+n])
    for n_graph in ngraphs:
        nums.append(convert_to_num(n_graph))
    for num in nums:
        texts.append(convert_to_text(((a*(num)+b)%26),n))
        ''.join(texts)
    return texts
text = "THEQUICKBROWNFOXJUMPEDOVERTHELAZYDOG"
enc = affine_n_encode(text, 5, 347, 1721)

print(enc)
Edit: Please let me know if you need any more information about the function to understand the problem
Reply
#2
Quite obviously while if len(text) % n==0: is not True nothing than empty list could be returned.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Is the else in line 8 supposed to line up with the if in line 5?

I think you want to pad out the text to a multiple of n, but I don't know why you are doing that.

Where are convert_to_num and convert_to_text?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why does this function print empty list? hhydration 1 1,520 Oct-28-2020, 02:03 AM
Last Post: deanhystad
  [supernoob] Can't spot the error... sidon 2 2,095 Jul-12-2019, 12:19 PM
Last Post: sidon
  why is this not filling my empty list? Siylo 4 3,137 Jan-21-2019, 05:27 PM
Last Post: Siylo
  help returning a list lga13 1 2,045 Dec-01-2018, 10:18 PM
Last Post: Larz60+
  Why is this function returning none? wlsa 2 5,791 Sep-30-2018, 01:36 PM
Last Post: gruntfutuk
  Issues with Inserting Values into an Empty List with a While Loop TommyMer 2 3,755 Sep-12-2018, 12:43 AM
Last Post: TommyMer
  why is the append function gets empty on the loop?/python rhai 3 3,200 Jul-07-2018, 12:19 PM
Last Post: rhai
  Function not returning correct value TsG009 4 4,121 Nov-24-2017, 09:07 PM
Last Post: sparkz_alot
  Function for returning absolute numbers Ernstblack 2 3,176 Oct-02-2017, 05:48 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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