python 3列表 操作
python 3列表的练习,随时编辑更新
#!user bin/env python
#coding=utf-8
import time
import sys
log = list(r’print(logshort[0][0][0])’)
‘’’
print(time.process_time_ns())
for i in range(0,1000):
#log[2]=“M”
log[-1:]+“1”
print(log)
print(time.process_time_ns())
‘’’
print(bytes(“hello,word”,encoding=‘utf-8’))
sdudent =[[“lei”,“123”],[“chen”,“a12”],[“kong”,“j22”]]
evanka = [“chen”,“a12”]
#evanka.remove(‘a12’)#删除指定元素,对多维列表无效
#sdudent.remove(‘a12’)验证对多维列表无效
print(type(evanka),evanka)
print(sdudent)
pass1 = “chen”
print(pass1 in sdudent)
word= “a12”
print(word in evanka)
print(evanka.index(“a12”))
x=[pass1,word]
if x in sdudent :print(“y”)
sys.argv
eli = [“chen”,56,‘7’,186,87,109]
eli_list = [str(i) for i in eli] #列表数值转字符串
print(eli,’\n’,eli_list,type(eli_list))
eli_list.sort(reverse=True) #并没有按升序排列????
print(eli_list)
def takeSecond(elem): #使用sdudent第2个元素
return elem[1] #进行
sdudent.sort(key=takeSecond) #排序
print(sdudent)
scale_1= [“0-15”,“50-150”,“500-2000”,“2000+”,“150-500”,“15-50”]
get_list = sorted(scale_1,key=lambda x: int(x.split(’-’)[0])if “-” in x else int(x.split("+")[0]))
print(get_list)
#for x,y in scale_1: #不能像字典一样key:赋值给x,y
#print(x,y,type(x))