0

Below is the code:

data2 = [["jsdfgweykdfgwey",
          "kdgwehogfdoyeo",
          "ndlgyehwfgdiye",
          "ndfluiwgmdfho"],
          ["---------------------------------------------------------------------------------",
           "-------------------------------------------------------------------------------",
           "------------------------------------------------------------------------------",
           "-----------------------------------------------------------------------------"],
          ["kdglwduifgeuifeudiwfkjkedluefywduifkcjkewfgpt1",
           "kdglwduifgeuifeudiwfkjkedluefywduifkcjkewfgpt2",
           "kdglwduifgeuifeudiwfkjkedluefywduifkcjkewfgpt3",
           "kdglwduifgeuifeudiwfkjkedluefywduifkcjkewfgpt4\
kdglwduifgeuifeudiwfkjkedluefywduifkcjkewfgpt4 \
kdglwduifgeuifeudiwfkjkedluefywduifkcjkewfgpt4"]]

data = [x for x in data2 if x is not None]
col_width = max(len(word) for row in data for word in row) + 2
for row in data:
    print "".join(word.ljust(col_width) for word in row)#print in single line in output console.

It is not printing output properly

How to print output in single line in command output (OS Linux)

or any other suggestions to print in column wise for long line printing.

abc
  • 165
  • 2
  • 10
  • 1
    Can you show what you want the output to look like? –  Mar 08 '18 at 14:42
  • 1
    Possible duplicate of [How to print without newline or space?](https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space) –  Mar 08 '18 at 14:42
  • what should the output look like? print everything in data2? `print "".join([item for items in data2 for item in items])` – Jonas Mar 08 '18 at 14:44
  • Because of long line printing, console output showing printing in new lines. its confusing to read out output. so I am reducing output print for each line – abc Mar 08 '18 at 15:17

1 Answers1

0

Each element in your list is printed out as a combined string as you wished. But by doing the word.ljust(col_width) step, where col_width is about 140, you are taking up a lot of empty space for printing. If your console size is small it will seem like you are printing in a new line. Try to replace col_width by 10, you will probably get the elements of data2[0] printed in one line.

If you want data2 to be printed as a single string then you can do the following:

tmp=''
for row in data:
    a = " ".join(word.ljust(col_width) for word in row)
    tmp = tmp + a

tmp will contain each element of data2 in a string one after the other

Zsolt Diveki
  • 159
  • 8