python - How to display a 2D list in this form? -


how can convert 2d list this?

lista=[[1, 2, 3],[3, 4, 5],[8, 5, 9]]   listb=[[1 2 3]        [3 4 5]        [8 5 9]] 

as pointed out, have same representation of 1 list in python, list list conversion doesn't make sense. however, if want list string conversion - ways output list nice string, have option of pprint, or pretty-printing. module standard library seems pretty close you're looking for:

import pprint  l = [[1, 2, 3],[3, 4, 5],[8, 5, 9]]  pprint.pprint(l, width=12) 

gives output

[[1, 2, 3],  [3, 4, 5],  [8, 5, 9]] 

now i've had artificially reduce maximum width bit lists short pprint, default, not consider them worth shortening.

also, if want string representation in program, can use pprint.pformat in pretty same way, except returns string:

import pprint  l = [[1, 2, 3],[3, 4, 5],[8, 5, 9]]  s = pprint.pformat(l, width=12) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -