Ask Your Question
0

converting a list to a text without copy-pasting

asked 2014-10-01 12:02:41 +0100

algebraicallyclosed gravatar image

Hi, I have a list and I need to convert it to a text but i want to call this list, so I don't want to copy and paste the result in text = " "

I tried text = list(U) (just assume that U is callable, so list(U) gives anything in U as a list) but it didn't work.

Can anyone suggest a way?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-10-01 14:31:27 +0100

calc314 gravatar image

updated 2014-10-01 14:32:37 +0100

I will assume your list consists of strings. You can build a string using a loop.

L=['a','b','c']
text=''
for s in L: 
     text+=s

Or, more succinctly, you can use the python join command:

newtxt=''.join(L)
print newtxt
edit flag offensive delete link more
0

answered 2014-10-16 18:03:18 +0100

algebraicallyclosed gravatar image

updated 2014-10-16 18:05:25 +0100

Thank you for answering. However, not those, but this worked; where

L = list(U); text = ''+str(L)

-For anyone who is also interested:)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-10-01 12:02:41 +0100

Seen: 839 times

Last updated: Oct 16 '14