I have two lists of coordinates:
[37.773972, -122.431297]
[37.773972, -122.45]
I want to create a list of tuples like so:
[(37.773972, -122.431297), (37.773972, -122.45)]
I've tried using zip but that merges the two.
thanks
I have two lists of coordinates:
[37.773972, -122.431297]
[37.773972, -122.45]
I want to create a list of tuples like so:
[(37.773972, -122.431297), (37.773972, -122.45)]
I've tried using zip but that merges the two.
thanks
>>> lst1 = [37.773972, -122.431297]
>>> lst2 = [37.773972, -122.45]
>>> res = [tuple(lst1), tuple(lst2)]
>>> res
[(37.773972, -122.431297), (37.773972, -122.45)]
How about this:
l1 = [37.773972, -122.431297]
l2 = [37.773972, -122.45]
merged = [tuple(l1), tuple(l2)]
print(merged) # [(37.773972, -122.431297), (37.773972, -122.45)]
You can convert a list into tuple using tuple(list name). Like:
def convert(list):
return tuple(list)
list = [a, c, b, d]
print(convert(list))
Here I define a function which is stored as a list and then I return it as a tuple. I give the input for list and finally when I print the defined function, It displays a tuple format of the list given.
list1 = [37.773972, -122.431297]
list2 = [37.773972, -122.45]
tup=[tuple(list1),tuple(list2)]
print(tup)