0

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

4 Answers4

3
>>> lst1 = [37.773972, -122.431297]
>>> lst2 = [37.773972, -122.45]
>>> res = [tuple(lst1), tuple(lst2)]
>>> res
[(37.773972, -122.431297), (37.773972, -122.45)]
Mohamed Yasser
  • 641
  • 7
  • 17
1

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)]
SimoX
  • 250
  • 6
  • 13
0

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.

chrslg
  • 9,023
  • 5
  • 17
  • 31
0

list1 = [37.773972, -122.431297]

list2 = [37.773972, -122.45]

tup=[tuple(list1),tuple(list2)]

print(tup)