3/07/2019

python number list, remove duplication and sort

coordiX = [0, 5016, 40, 5012, 40, 5012, 40, 5012, 40, 5012, 3169, 4970, 3169, 4970, 3169, 4970, 3169, 3537, 3586, 4355, 4395, 4970, 2632, 4616, 2632, 4616, 2632, 4616, 2632, 4616, 3651, 3659, 3651, 3659, 3651, 3659, 3651, 3659, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2632, 4616, 2632, 4616, 2632, 4616, 2632, 4616, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2632, 4614, 2632, 4614, 2632, 4614, 2632, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 2640, 2630, 2640, 2630, 2640, 2630, 2640, 3652, 3660, 3652, 3660, 3652, 3660, 3652, 3660, 328, 4670, 328, 4670, 328, 4670, 328, 4670, 328, 4668, 328, 4668, 328, 4668, 328, 4668, 330, 4614, 330, 4614, 330, 2962, 330, 784, 808, 1206, 2694, 2962, 2692, 3868, 2692, 3404, 3428, 3868, 332, 866]

print("origin")
print(coordiX)
print("length:", len(coordiX))

print("remove duplication")
coordiX = list(set(coordiX))
print(coordiX)
print("length:", len(coordiX))

print("sort")
coordiX.sort()
print(coordiX)

output
origin
[0, 5016, 40, 5012, 40, 5012, 40, 5012, 40, 5012, 3169, 4970, 3169, 4970, 3169, 4970, 3169, 3537, 3586, 4355, 4395, 4970, 2632, 4616, 2632, 4616, 2632, 4616, 2632, 4616, 3651, 3659, 3651, 3659, 3651, 3659, 3651, 3659, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2632, 4616, 2632, 4616, 2632, 4616, 2632, 4616, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2632, 4614, 2632, 4614, 2632, 4614, 2632, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 4614, 2630, 2640, 2630, 2640, 2630, 2640, 2630, 2640, 3652, 3660, 3652, 3660, 3652, 3660, 3652, 3660, 328, 4670, 328, 4670, 328, 4670, 328, 4670, 328, 4668, 328, 4668, 328, 4668, 328, 4668, 330, 4614, 330, 4614, 330, 2962, 330, 784, 808, 1206, 2694, 2962, 2692, 3868, 2692, 3404, 3428, 3868, 332, 866]
length: 130

remove duplication
[0, 3586, 4355, 2692, 4614, 2694, 4616, 784, 2962, 5012, 5016, 3868, 40, 808, 4395, 1206, 4668, 4670, 3651, 3652, 2630, 2632, 328, 330, 3659, 3660, 3404, 332, 2640, 3537, 3169, 866, 3428, 4970]
length: 34

sort
[0, 40, 328, 330, 332, 784, 808, 866, 1206, 2630, 2632, 2640, 2692, 2694, 2962, 3169, 3404, 3428, 3537, 3586, 3651, 3652, 3659, 3660, 3868, 4355, 4395, 4614, 4616, 4668, 4670, 4970, 5012, 5016]

No comments:

Post a Comment