import os,random,sys,time import string print(random.randint(1,100))#包含100 print(random.uniform(1,10))#小数 print(random.choice(string.ascii_lowercase))#随机选择一个值,可循环的就行 print(random.sample(string.ascii_lowercase,3))#随机选择n个值,可循环的就行 l2=random.sample(string.digits,6)#不可能会重复 l=[random.choice(string.digits) for i in range(6)]#可能会重复 print(l2) print(l) l1 =[1,2,3,4,5] random.shuffle(l1)#打乱顺序 print(l1) #可对字符串排序 l1 = sorted(l1)#排序,升序 l1 = sorted(l1,reverse=True)#排,降序 print(l1) d={ ‘zjr‘:100, ‘aa‘:78, ‘tt‘:98 } print(d.items())#dict_items([(‘zjr‘, 100), (‘aa‘, 78), (‘tt‘, 98)]) res = sorted(d.items(),key=lambda x:x[1],reverse=True) print(res)
原文:https://www.cnblogs.com/Mezhou/p/13616243.html