Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python list to newline separated value


Im trying to get data in pylon to use in jquery autocomplete, the librarary i'm using for autocomplete it requires this format

abc
pqr
xyz

and in python i have data in this format

[["abc"], ["pqr"],["xyz"]

How do i convert this list to the above one.

Edit:
I trying to use these for a autocompete and i'm using pylons, in which the query to the server return list in this format

    [["abc"], ["pqr"],["xyz"]

http://jquery.bassistance.de/autocomplete/demo/ this library except remote call in

abc 
pqr
xyz

i tried to use

"\n".join(item[0] for item in my_list)

but it returns data in firebug like this.

'asd\ndad\nweq'

i want it to be in

abc
pqr
xyz

any help would be appreciated as i'm a PHP developer this is first time i'm trying to do code in python.

thnaks

like image 661
m4k Avatar asked Aug 26 '26 12:08

m4k


2 Answers

"\n".join(item[0] for item in my_list)

However, what's this got to do with JSON...?

like image 130
Matti Virkkunen Avatar answered Aug 29 '26 03:08

Matti Virkkunen


I am not exactly sure what you want, but you may try:

nested_list = [ ["abc"], ["pqr"], ["xyz"] ]
data = "\n".join( (item[0] for item in nested_list) )

This will convert your list of lists into a string separated by newline characters.

like image 29
Jim Brissom Avatar answered Aug 29 '26 03:08

Jim Brissom