简体   繁体   中英

How to convert a float list to a tuple list by pair?

Assuming that the length of the list is always even, what is the best way to convert the following list:

points = [[1437.8552278820375, 1187.3458445040214, 1084.396782841823, 1245.6836461126006, 1104.9865951742627, 1430.9919571045577, 1458.4450402144773, 1307.4530831099196]]

to a tuple list such as:

points = [(1437.8552278820375, 1187.3458445040214), (1084.396782841823, 1245.6836461126006), (1104.9865951742627, 1430.9919571045577), (1458.4450402144773, 1307.4530831099196)]
points = zip(points[0][::2], points[0][1::2])
list(points)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM