Python> tuple> Convert double tuple to single tuple

Operating environment


Xeon E5-2620 v4 (8 cores) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 and its-devel
mpich.x86_64 3.1-5.el6 and its-devel
gcc version 4.4.7 (And gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Use 1.
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

--Method 1: Process with double for in list

code

test_python_170323d.py


atuple = ((3, 1, 4), (1, 5, 9), (2, 6, 5))
print(atuple)

# 1 
res = [ flatten for inner in atuple for flatten in inner ]
res = tuple(res)
print(res)

# 2
res = ()
for rows in atuple:
	res = res + rows

print(res)

result


$ python test_python_170323d.py 
((3, 1, 4), (1, 5, 9), (2, 6, 5))
(3, 1, 4, 1, 5, 9, 2, 6, 5)
(3, 1, 4, 1, 5, 9, 2, 6, 5)

Method 1 takes a long time to understand (Time-till-understanding in Readable code) after reading the code.

For the time being, let's use the implementation of Method 2.

Recommended Posts

Python> tuple> Convert double tuple to single tuple
Python> list> Convert double list to single list
python> Convert tuple to list> aList = list (pi_tuple)
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
Convert python 3.x code to python 2.x
Convert markdown to PDF in Python
Workflow to convert formula (image) to python
Convert list to DataFrame with python
[Python] Convert natural numbers to ordinal numbers
Convert decimal numbers to n-ary numbers [python]
[Python] How to convert db file to csv
Convert memo at once with Python 2to3
Convert Python> two value sequence to dictionary
[Python] How to convert a 2D list to a 1D list
How to convert Python to an exe file
[Python] Convert csv file delimiters to tab delimiters
Convert psd file to png in Python
[Introduction to Udemy Python3 + Application] 21. Tuple type
Convert Excel data to JSON with python
Convert from katakana to vowel kana [python]
Single pixel camera to experience with Python
Convert FX 1-minute data to 5-minute data with Python
Convert Python date types to RFC822 format
Convert HEIC files to PNG files with Python
Convert from Markdown to HTML in Python
Convert absolute URLs to relative URLs in Python
Sample to convert image to Wavelet with Python
[Introduction to Udemy Python 3 + Application] 22. Tuple unpacking
Updated to Python 2.7.9
Convert to HSV
Python> tuple> tuple unpacking
"Backport" to python 2
Python code to convert region mesh code to latitude / longitude
Convert PDF to image (JPEG / PNG) with Python
Convert "number" of excel date to python datetime
Convert PDFs to images in bulk with Python
[Python] Convert from DICOM to PNG or CSV
Convert Windows epoch values to date with python
How to convert SVG to PDF and PNG [Python]
Python> tuple> (3., 1., 4.) to 3.00000, 1.00000, 4.00000 (decimal point to 5 digits)> Use .join
[Python] How to use hash function and tuple.
Convert STL to Voxel mesh using Python VTK
Convert exponential notation float to str in Python
Convert cubic mesh code to WKT in Python
Convert strings to character-by-character list format with python
Convert timezoned date and time to Unixtime in Python2.7
Convert jupyter notebook .ipynb files to python executable .py files
Python practice Convert the input year to the Japanese calendar
How to convert / restore a string with [] in python
[Python] Convert decimal numbers to binary numbers, octal numbers, and hexadecimal numbers
How to convert Python # type for Python super beginners: str
How to install Python
[Python] Convert general-purpose container and class to each other
Convert 202003 to 2020-03 with pandas
Changes from Python 3.0 to Python 3.5
Convert NumPy array "ndarray" to lilt in Python [tolist ()]
Changes from Python 2 to Python 3.0
Convert CIDR notation netmask to dotted decimal notation in Python