Skip to content
Advertisement

Tag: unpack

Is it possible to unpack values from list to slice?

I’m trying to use values in list to select part of word. Here is working solution: but I wonder if is it possible to shorten it? Something like this comes to my mind: It produces: Answer You can use the built-in slice (and need to name your list differently to be able to access the built-in):

What does the comma mean in Python’s unpack?

We can simply use: why do people write it like this: What does the comma mean? Answer The first variant returns a single-element tuple: To get to the value, you have to write crc[0]. The second variant unpacks the tuple, enabling you to write crc instead of crc[0]:

Advertisement