0
list = [["acd",2,"b"],["c",33,"d"],["e","f",4]]

This is my list.

i want to print like

acd 2  b
c   33 d
e   f  4
4
  • 1
    Could you show what have you tried? You must show some effor while asking in StackOverflow. Commented Jan 18, 2014 at 6:36
  • check this answer : link Commented Jan 18, 2014 at 6:38
  • I have no idea what you mean by "print in to website". Are you trying to insert into an existing html document? Create a new one? Do you want to make some kind of <table> layout, or just what? Commented Jan 18, 2014 at 8:23
  • yeah you said it. I just only want to print like that.But i was not able to put the title as what i want while asking question So i tried crazy :P Commented Jan 18, 2014 at 14:35

2 Answers 2

1

You can use a comma to keep printed output on the same line. For example

# don't name a list 'list' in python
lst =  [["acd",2,"b"],["c",33,"d"],["e","f",4]]

for sub in lst:
    for item in sub:
        # for each item in the sublist, print it on a single line
        print item,
    # at the end of each sublist, print a new line
    print ''

To get the output exactly like your example in the question, you'll have to use conditionals to check the size of each item and adjust the amount of spaces it should have before it. But this should be enough to get you started.

Sign up to request clarification or add additional context in comments.

Comments

1

Here's a one-liner :)

>>> print "\n".join("\t".join(map(str, item)) for item in list)
acd 2   b
c   33  d
e   f   4

PS: I'll echo what@samrap says: Don't use list as variable names.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.