# python 如何实现某个元素上下移动

0
[已解决问题] 解决于 2017-01-07 16:32



LiZR07 | 菜鸟二级 | 园豆：208

0
```# -*- coding: utf-8 -*-
"""
:created on: 2016年12月23日

:author:画船听雨眠
:contact:ceet@vip.qq.com
"""
'''
[(2.0,2.1),(2.1,2.0),(2.0,2.0),(4.0,4.0),(4.1,4.2),(4.2,4.1),(3.1,2.9)]，现在要

'''
import math

def distance_of_two_point(x, y):
return math.sqrt(math.pow(x[0] - y[0], 2) + math.pow(x[1]- y[1], 2))

def compare(index):
def compare_item(x, y):
if distance_of_two_point(index, x) > distance_of_two_point(index, y):
return 1
else:
return -1
return compare_item

def deal_list(list_in):
for index in list_in:
temp = [items for items in list_in if items != index]
print temp
temp = sorted(temp, compare(index))
print temp
print
a = []
for number, item in enumerate(temp):
a.append(distance_of_two_point(index, item))
print a

list_in = [(2.0,2.1),(2.1,2.0),(2.0,2.0),(4.0,4.0),(4.1,4.2),(4.2,4.1),(3.1,2.9)]
deal_list(list_in)
if __name__ == '__main__':
pass```

0



LiZR07 | 园豆：208 (菜鸟二级) | 2016-12-22 19:42

您需要登录以后才能回答，未注册用户请先注册