Unpacking a List in Python

  • Comments posted to this topic are about the item Unpacking a List in Python

  • Just a heads up, it looks like one of the answer options didn't populate in the textbox correctly.

    Here's the exception for the question option, if it's not too late:

    This will not work. A ValueError will be raised with the following exception:

    ValueError: not enough values to unpack (expected 4, got 3)
  • Hadn't got to this in my Python Ed. I can see this being useful.

  • Learned something new!

    I knew about this one:

    t = ['a', 'b', 'c']
    print(*t)

    The unpacking thing is cool, can put the asterisk in the middle too:

    for name in [("First","Last"), ("First", "Middle1", "Middle2", "Last")]:
    first, *middle, last = name
    print(f"{first}, {middle}, {last}\n-----")

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply