#Returning a list from Packing in python

2 messages · Page 1 of 1 (latest)

visual wraith
#

Hey everyone!
I'm currently on the packing and unpacking module from the learning path in python and everytime I'm trying to return a list from packing I get the error from the image below, this is my code so far:

    a, b, c, *rest = each_wagons_id
    last_items = [a,b]
    *corrected_wagons = c, *missing_wagons, *rest, *last_items
    return corrected_wagons

I've tried changing the corrected_wagons to this corrected_wagons = [c, *missing_wagons, *rest, *last_items] and it worked, but I would like to know if I 'm doing something wrong/different than I should in the original code

trail cliff
#

The left-hand side needs to be a list or a tuple. *corrected_wagons is neither so you need to wrap it in a list like [*corrected_wagons] = .... Or you could write it a single-element tuple like as (*corrected_wagons,) = ... which can be simplified as *corrected_wagons, = ....