Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

unpacking

"""Pythonic Unpacking
"""
## Unpacking iterables
lst = [1, 2, 3]
a, b, c = lst
print(a, b, c)
# a = 1, b = 2, c = 3

## The use of * for unpacking iterables
v, *end = [1, 2, 3, 4]
print(v, end)
# v = 1, end = [2, 3, 4]

v, *middle, z = [1, 2, 3, 4]
print(v, middle, z)
# v = 1, middle = [2, 3], z = 4

*v, end = [1, 2, 3, 4]
print(v, end)
# v = [1, 2, 3], end = 4


"""Try out other iterables to unpack!"""
Comment

unpack

# unpack list
x = [1,2,3,4,5]
print(*x)		# return 1 2 3 4 5
Comment

PREVIOUS NEXT
Code Example
Python :: how to get the original start_url in scrapy 
Python :: iterate 
Python :: > not supported between tuple and int 
Python :: python calculate area diameter circumference circle 
Python :: bson to dataframe pandas 
Python :: how to convert nonetype to list in python 
Python :: group by quintiles pandas 
Python :: apk calculate python 
Python :: uri beecrowd problem 1047 Game Time with Minutes 
Python :: plotly dcc.interval bar graph with time 
Python :: # difference between list 1 and list 2 
Python :: Linear Search Python with enumerate 
Python :: Data Analytics with Pandas – How to Drop a List of Rows from a Pandas Dataframe 
Python :: python online compiler with libraries 
Python :: split list in two based on condition python 
Python :: BIDS extract JSON data 
Python :: Using Python Permutations function on a String with extra parameter 
Python :: extract tables from image python 
Python :: copy director structure python 
Python :: python set vs tuple performance 
Python :: mk270 suits for programming reddit 
Python :: python new set 
Python :: Python NumPy atleast_3d Function Example 2 
Python :: text xml 
Python :: Python NumPy ascontiguousarray Function Syntax 
Python :: tensorflow configure multiple gpu 
Python :: merge pdf with python at same page 
Python :: NumPy rot90 Example Rotating four times 
Python :: NumPy invert Code When inputs are Boolean 
Python :: selenium python select elements data atribute 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =