I have a 2D list of characters this way:
a = [['1','2','3'], ['4','5','6'], ['7','8','9']]
What is the most pythonic way to print a list as a whole block? That is, there are no commas or brackets:
123 456 789
There are many ways. Probably a str.joinmapping str.joins:
str.join
>>> a = [['1','2','3'], ... ['4','5','6'], ... ['7','8','9']] >>> print('\n'.join(map(''.join, a))) 123 456 789 >>>
Like this:
import os array = [['1','2','3'], ['4','5','6'], ['7','8','9']] print(os.linesep.join(map(''.join, array)))
Pythonic, :
print('\n'.join(''.join(i) for i in array))
, -, print. print ( ).
print
>>> a = [['1','2','3'], ... ['4', 5, 6], # Contains integers as well. ... ['7','8','9']] ... >>> for x in a: ... print(*x, sep='') ... ... 123 456 789
Python 2, from __future__ import print_function.
from __future__ import print_function
Source: https://habr.com/ru/post/1681171/More articles:How to use firebase account using expo - react-nativeA page-specific script, along with third-party scripts and application scripts in Webpack - javascriptStrange LSTM training loss curve with Keras - deep-learningJava thread filtering - javaI want to show the duration of a vacation at a floating cost - pythonChoosing the first element from a Python tuple - pythonDomain Error = NSCocoaErrorDomain Code = -1 "(null)" when moving .mov to camera frame - iosAre the variables declared in the .bss section of NASM loaded into the process data section, not the process bss section? - assemblyHow to separately obtain user and system environment variables in Windows using C - cXamarin binds default value in xaml - androidAll Articles