Python string from list comprehension

You need to join your string like this:

markers = [(97,64),(45,84)]
result = ''.join("&markers=%s" % ','.join(map(str, x)) for x in markers)
return result

UPDATE

I didn’t initially have the ','.join(map(str, x)) section in there to turn each tuple into strings. This handles varying length tuples, but if you will always have exactly 2 numbers, you might see gatto’s comment below.

The explanation of what’s going on is that we make a list with one item for each tuple from markers, turning the tuples into comma separated strings which we format into the &markers= string. This list of strings is then joined together separated by an empty string.

Leave a Comment

tech