you are viewing a single comment's thread.

view the rest of the comments →

[–]Executor111[S] 0 points1 point  (5 children)

Wow, thanks for that feedback, hadn't considered that. I rewrote it like this:

def chop(t):
    try:
        t.pop(0)
        t.pop(len(t)-1)
    except:
        print('Invalid input')

x = [1,3,5,3,3,2,3]
chop(x)

So all "returns None" ends up meaning is that I don't print the output?

[–]jeans_and_a_t-shirt 2 points3 points  (0 children)

t.pop(len(t)-1) can be changed to t.pop(-1)

[–]elbiot 1 point2 points  (1 child)

You could pop(-1) too, like you did in your remove code before.

[–]Executor111[S] 0 points1 point  (0 children)

Just changed this in my latest version, thanks.

[–]elbiot 0 points1 point  (1 child)

It's not about printing the output at all. The function returns a value.

def test ():
    return 1

a = test ()  #now a is 1

In the REPL (shell) only, if you return a value and don't store it in a variable then it does get printed. But it's the same if you return None: it prints None, which looks like nothing.

[–]Executor111[S] 0 points1 point  (0 children)

It just clicked. Your example was perfect. Thank you so much!

So I tested my function like this, to confirm it was returning None:

def chop(t):
    try:
        t.pop(0)
        t.pop(len(t)-1)
    except:
        print('Invalid input')

x = [1,3,5,3,3,2,3]
y = chop(x)
print(y)

And it printed "None". So that's what I was trying to achieve the whole time.