将一个列表拆分成具有重叠元素的元组列表。

huangapple go评论63阅读模式
英文:

Split a list into list of tuple with overlapping elements

问题

我想要将列表分割成元组列表,其中第二个元素变成元组的第一个元素

例如:期望输出:

temps = [(-39.5, -27.5), (-27.5,-15.5), (-15.5,-3.5), (-3.5,8.5), (8.5,20.5), (20.5,32.5), (32.5,44.5), (44.5,56.5), (56.5,68.5), (68.5,80.5), (80.5,92.5), (92.5,104.5)]

英文:

I have a list which looks like this:
temp=[-39.5, -27.5, -15.5, -3.5, 8.5, 20.5, 32.5, 44.5, 56.5, 68.5, 80.5, 92.5,104.5]

I want to split the list into list of tuple where second element becomes the first element of the tuple

e.g.: Expected output:
temps = [(-39.5, -27.5), (-27.5,-15.5), (-15.5,-3.5), (-3.5,8.5), (8.5,20.5), (20.5,32.5), (32.5,44.5), (44.5,56.5), (56.5,68.5), (68.5,80.5), (80.5,92.5), (92.5,104.5)]

huangapple
  • 本文由 发表于 2023年6月2日 00:06:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定