Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert array to string in python? [duplicate]

Tags:

python

i have array like below

arr = [1,2,3]

how can i convert it to '1,2,3' using python

i have a usecase where i want to add a filter parameter to url like below

url = some_url?id__in=1,2,3

i was initially thinking to pass it like so

url = some_url?id__in={arr} 

but this is incorrect. i am new to python and i have browsed how to do this.

" ".join(str(x) for x in arr)

but this will give output '1 2 3'

how can i fix this. could someone help me with this. thanks.

like image 969
stackuser Avatar asked Apr 20 '26 13:04

stackuser


1 Answers

This gives you the 1,2,3 that you asked for.

",".join(str(x) for x in arr)

like image 61
Joshua Fox Avatar answered Apr 23 '26 01:04

Joshua Fox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!