0

I have a list containing some coordinates ordered as tuples:

list =    [(316852,4.99246e+06), (316858,4.99244e+06), (316880,4.99246e+06), (316863,4.99248e+06), (316852,4.99246e+06)]

and I would like to get its elements by group of 2. The result expected is something like this:

(316852,4.99246e+06), (316858,4.99244e+06)
(316858,4.99244e+06), (316880,4.99246e+06)
(316880,4.99246e+06), (316863,4.99248e+06)
(316863,4.99248e+06), (316852,4.99246e+06)

Any idea on how to obtaining this?

mgri
  • 267
  • 1
  • 3
  • 13

2 Answers2

1

Something like this?

list = [(316852,4.99246e+06), (316858,4.99244e+06), (316880,4.99246e+06), (316863,4.99248e+06), (316852,4.99246e+06)]

for x in range(0, len(list)-1):
    print(list[x], list[x+1])
Filip Haglund
  • 13,919
  • 13
  • 64
  • 113
  • Thanks dude, I didn't think about decreasing the counter by 1! In this way, the task has become easier =) – mgri Dec 09 '16 at 12:30
-1

you can try this :

print([list[i:i+2] for i in range(0,len(list),2)])
akash karothiya
  • 5,736
  • 1
  • 19
  • 29
  • 3
    Please use the [edit] link explain how this code works and don't just give the code, as an explanation is more likely to help future readers. – Jed Fox Dec 09 '16 at 13:21