I have two list named results and p_results. I want to show those list values in table like if
results = [1,2,3,4]
p_results = [5,6,7,8]
I want something like this
1 5
2 6
3 7
4 8
print('{:3}{:20}'.format(results, p_results))
running the code:
runfile('D:/4/2d.py', wdir='D:/4')
Traceback (most recent call last):
File "<ipython-input-59-1abb0c96f0c0>", line 1, in <module>
runfile('D:/4/2d.py', wdir='D:/4')
File "C:\Users\Rabinsen\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "C:\Users\Rabinsen\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/4/2d.py", line 61, in <module>
print('{:3}{:20}'.format(results, p_results))
TypeError: unsupported format string passed to list.__format__
Kenil Vasani
You can pass a
list
type toformat
(using just{}
), but the formatting you requested isn’t available. And the standard formatting isn’t suited anyway, so…What you want is each list on one separate column. You’ll have to
zip
lists together, and iterate on the result to pass it to format:That prints something like: