0

I have a list of columns that I am trying to show as multiple columns:

Given below is the list:

for name in file:
    worksheet.write(row, col, name)
    col += 1

Given below is the output created:

['apples','oranges','bananas','pears']

I am trying to transpose it and have it displayed as below :

apples
oranges
bananas
pears

Could anyone advice how could I get my list transposed. Thanks

0

3 Answers 3

1

If I'm getting it right you want this:

[list(item) for item in your_list]

This will create a 2d list, each item of which in it's own 'row'.

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

Comments

0

Changing the col increment to row increment will solve your problem.

for name in file:
    worksheet.write(row, col, name)
    row += 1

Output:

apples
oranges
bananas
pears

Comments

0

Use join:

print('\n'.join(your_list))

join can do what you want.

Output:

apples
oranges
bananas
pears

4 Comments

tried the above but it still displays each of the items in the list in separate columns but does not transpose it by row..
@hellokee What's the desired output then?
I am trying to have these values displayed in different rows but same column.. I am not sure if I am expressing how I want. If you refer to the expected output I shared in my initial message, each of the items of the list are displayed one below the other but in the same column.. hope this helps.. Tnx
@hellokee Doesn't mine do that? can you please run it again?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.