zoukankan      html  css  js  c++  java
  • Python:对列表进行排序并相应地更改另一个列表?

    我有两个列表:一个包含一组x点,另一个包含y点。我需要按照从最低到最高的顺序对x点的列表进行排序,并且移动y点以跟随它们的x个对应点。

    x = [3,2,1]
    y = [1,2,3]
    points = zip(x,y)
    points
    [(3, 1), (2, 2), (1, 3)]
    sorted(points)
    [(1, 3), (2, 2), (3, 1)]
    

    然后再打开它们:

    sorted_points = sorted(points)
    new_x = [point[0] for point in sorted_points]
    new_y = [point[1] for point in sorted_points]
    new_x
    [1, 2, 3]
    new_y
    [3, 2, 1]
    

    来自:https://cloud.tencent.com/developer/ask/54457

  • 相关阅读:
    hihocoder 1038
    hihocoder 1039
    poj 2774
    bzoj 4690&&4602
    poj 2417
    STL
    poj 1026
    poj 1064
    poj 1861(prim)
    poj 1129
  • 原文地址:https://www.cnblogs.com/USTC-ZCC/p/12886437.html
Copyright © 2011-2022 走看看