当前位置:首页>开发>正文

python中通过特定条件进行创建列表 python列表排序

2023-04-23 18:09:16 互联网 未知 开发

 python中通过特定条件进行创建列表 python列表排序

python中通过特定条件进行创建列表

is_count = True
name = []
while is_count:
a = input()
if a in a and name.count(a) <= 10 :
name.append(a)
elif name.count(a) > 10:
break

else:

pass

python列表排序

[(i,j) for j,i in sorted([(a,b) for b,a in l], reverse = True)]

这样也可以
l.sort(key = lambda x:x[1],reverse = True)

Python中字典按照指定列表的顺序排列

roles =["OWNER", "RCOM", "HRGDL2", "HRM", "HRH", "MP", "HP", "VP", "GM"]
info ={"VP": "80003", "HRM": "F140019", "MP": "F130008", "HRGDL2": "F140390", "OWNER": "F133255", "RCOM": "F900151", "GM": "00903", "HP": "80355", "HRH": "81453"}
sorted_dict =map(lambdax:{x:info[x]}, roles)
print(sorted_dict)

python按某一内部列表排序

#!/usr/bin/env python# coding=utf-
import itertools
def sort_by_2nd_list(list0):
    list_of_tuple = itertools.izip(*list0)
    sorted_list = sorted(list_of_tuple, key=lambda x: x[1])
    return [[x[i] for x in sorted_list] for i in range(len(list0))]
def test_sort_by_2nd_list():
    list1 = [A, B, C]
    list2 = [1.5, 1.2, 1.3]
    list3 = [1, 2, 3]
    list0 = [list1, list2, list3]
    assert sort_by_2nd_list(list0) == [[B, C, A],
                                       [1.2, 1.3, 1.5],
                                       [2, 3, 1]]

最新文章