Properly stuck: how do I append items to a list without including all of the lists contents up to that point?

Been stuck for like two hours on this problem:

def decodeforce(string1):
    decodedlist = []
    for index in range(3):
        decodedlist.append(decode(string1, index))
    return decodedlist

This is the output:

[‘a t o x’, ‘a t o x b u p y’, ‘a t o x b u p y c v q z’]

How do I append unique stuff (like b u p y in the second element of the list) without including everything that came before it? In other words what I want is [a t o x, b u p y, c v q z] etc.


Break it down into explicit clauses.
With the line decodedlist.append(decode(string1, index)) you have 2 things happening. Try to write this in 2 lines (verify with strategic prints) before doing a one-liner if it’s not coming out right.

def decodeforce(string1):
    decodedlist = []
    for index in range(3):
        print(decode(string1, index))
    return decodedlist


gives the following output:

a t o x
a t o x b u p y
a t o x b u p y c v q z

Still don’t understand why

Who wrote the decode() function? If you wrote it, you can adjust the behavior.

If not, it still works in a predictable way. Just leverage the fact that you know the length of change in each operation and make adjustment accordingly. Don’t be afraid to use temp variables as you work it out.

yea I found out a way to do it but why does it give that output?

What are the specs for the decode() function? You would have to look there if you didn’t write it.

yea looked through that too - –

alphabet = "abcdefghijklmnopqrstuvwxyz"
punctuation = ".,?'! "
newlist = []

def decode(string1, offset):
    newindice = 0
    for letters in string1:
        for indices in range(len(alphabet)):
            if letters == alphabet[indices]:
                if indices < (26 - offset):
                    newlist.append(alphabet[indices + offset])
                elif indices >= (26 - offset):
                    newindice = offset - (25 % indices) - 1
    return (" ").join(newlist)

it works fine tbh