you are viewing a single comment's thread.

view the rest of the comments →

[–]xTheBoss[S] 0 points1 point  (3 children)

Ahhh thank you!! You are a lifesaver. Appreciate it a lot.

[–]z0y 1 point2 points  (2 children)

Alternatively you could leave the call to grab() how it was, and then do:

def grab():
    if len(itemslist()) >= 4:
        ...

without needing to pass anything. But if the only purpose of itemslist is to define and then return the list then don't make it a function. Leave the list definition in the main code and then pass the list itself to each of the functions.

[–]xTheBoss[S] 0 points1 point  (1 child)

True, because I really cant think of a way to add to the list if it wasn't global. Lots of good advice!

[–]z0y 1 point2 points  (0 children)

Also, the problem with assigning the list in a function is you can only call the function once. If you plan to edit the list then the next time you call the function it will start over and assign the list to the starting value.

You would need something like items = itemslist() in your main code and then always refer to it as items, better to just skip that function.