<jupyter_start><jupyter_text>列表List- 一个列表可以储存任意大小的数据集合，你可以理解为他是一个容器  先来一个例子爽一爽![](../Photo/115.png)<jupyter_code>Num=5
number=[]
sum=0
for i in range(Num):
    value = eval(input('enter a new number:'))
    number.append(value)
    sum+=value
average=sum/Num
count=0
for i in range(Num):
    if  number[i]>average:
        count+=1
print('average is',average)
print('num of element above the average is ',count)<jupyter_output>enter a new number:6
enter a new number:7
enter a new number:3
enter a new number:4
enter a new number:5
average is 5.0
num of element above the average is  2<jupyter_text>创建一个列表- a = [1,2,3,4,5]<jupyter_code>num=[]
a=[1,2,[1,2,3,],3,4,5,True]
for i  in a:
    num.append(i)
print(num)
type(a)
list('asdf')
list([1,2,3])<jupyter_output><empty_output><jupyter_text>列表的一般操作![](../Photo/116.png)<jupyter_code>a2=[1,2,3,'haha',True]
100 not in a2
a3=[100,200,300,'lala',False]
a2+a3
a2*3
a2*50
len(a2)
a4=[1,2,3,4,5]
sum(a4)
summ=0
for i in a4:
    summ=summ+i
print(summ)
a5=[1,2,3]
a6=[1,5]
a5==a6<jupyter_output><empty_output><jupyter_text>列表索引操作- Mylist[index]- 正序索引，逆序索引- 列表一定注意越界- ![](../Photo/117.png)<jupyter_code>try:
    a2[3]
except Exception as e:
    print('发生未知错误')<jupyter_output>发生未知错误<jupyter_text>列表切片操作- Mylist[start:end]- 正序切片，逆序切片  列表 +、*、in 、not in  使用for循环遍历元素- for 循环可以遍历一切可迭代元素  EP：- 使用while 循环遍历列表  列表的比较- \>,=,<=,==,!=  列表生成式[x for x in range(10)]<jupyter_code>(lambda x : print(x))(10)
a=[x for x in range(10) if x%2==0]
a
a=[x for x in range(100) if x%2==0]
a
a=(x for x in range(10))
next(a)
next(a)
def test():
    yield "hahahh"
a1=test()
next(a1)<jupyter_output><empty_output><jupyter_text>列表的方法![](../Photo/118.png)<jupyter_code>a=[x for x in range(10)]
a.append(10)
a
a=[x for x in range(10)]
for i in 'joker':
    a.append(i)
a
b=[x for x in 'joker']
b
b.count('r')
b.extend(b)
b
b.index('j')
b.insert(4,[1,2,3])
b
b.remove('j')
b
b1=[1,2,3]
b1.reverse()
b1
a=[x for x in range(100)]
for j in range(1,len(a)):
    print(a[len(a)-j])
b2=[0,5,1,4,9]
b2.sort(reverse=True)
b2
b2=[0,5,1,4,9]
b2.sort()
b2
b2=[0,5,1,4,9]
for i in range(len(b2)):
    for j in range(i,len(b2)):
        if b2[i]>b2[j]:
            b2[i],b2[j]=b2[j],b2[i]
b2
b3=[['joker',180,['a',5]],['xiaoming',28,['b',1]],['xiaohua',1,['c',0],],['xiaoli',16,['d',5],]]
b3.sort(key=lambda x:x[2][1])
b3
sorted(b3,key=lambda x: x[0],reverse=False)
b4=[1,2,3]
b4.pop()
b4<jupyter_output><empty_output><jupyter_text>将字符串分割成列表- split  按照自定义的内容拆分<jupyter_code>b5='a,bc,d'
b5.split(',')<jupyter_output><empty_output><jupyter_text>EP:![](../Photo/119.png)![](../Photo/120.png)<jupyter_code>import random
lst=[30,1,2,1,0]
random.shuffle(lst)
lst<jupyter_output><empty_output><jupyter_text>列表的复制- copy 浅复制- deepcopy import copy  深复制- http://www.pythontutor.com/visualize.htmlmode=edit<jupyter_code>b5=[1,2,3,[100,200]]
b6=b5.copy()
b6
b6[0]=100
b6
b5
b6[3][1]=1000
b6
b5
import copy
b5=[1,2,3,[100,200]]
b6=copy.deepcopy(b5)
b6<jupyter_output><empty_output><jupyter_text>列表排序- sort- sorted- 列表的多级排序    - 匿名函数  EP：- 手动排序该列表[5,3,8,0,17]，以升序或者降序 - 1![](../Photo/121.png)<jupyter_code>from openpyxl.reader.excel import load_workbook
file = load_workbook(filename="C:\\Users\\Administrator\\Desktop\\AAA.xlsx")
name_list=file.sheetnames # 获取工作表名字
print(name_list)
sheet = file[name_list[0]]
#    工作表名字     使用的最大列，       使用的最大的行
print(sheet.title,sheet.max_column,sheet.max_row)
# a = sheet.cell(row=12,column=4).value  # 获取某行某列的具体值
# print(a)
# 遍历整个sheet表
for row in range(1,sheet.max_row+1):
    row_list = []
    for column in range(1,sheet.max_column+1):
        cell = sheet.cell(row=row,column=column).value
        #if cell:
        row_list.append(cell)
    print(row_list)
    
a1=input('enter scores:')
a1=a1.split(',')
b1=len(a1)
a1.sort()
print(a1)
for i in range(0,b1):
    if a1[i]>='90':
         print('srudent '+str(i)+' score is '+a1[i]+'and grade is A')
    elif a1[i]>='80':
         print('srudent '+str(i)+' score is '+a1[i]+'and grade is B')
    elif a1[i]>='70':
        print('srudent '+str(i)+' score is '+a1[i]+'and grade is C')
    elif a1[i]>='60':
        print('srudent '+str(i)+' score is '+a1[i]+'and grade is D')
    else:
        print('srudent '+str(i)+' score is '+a1[i]+'and grade is F')<jupyter_output>enter scores:40,55,70,58
['40', '55', '58', '70']
srudent 0 score is 40and grade is F
srudent 1 score is 55and grade is F
srudent 2 score is 58and grade is F
srudent 3 score is 70and grade is C<jupyter_text>- 2![](../Photo/122.png)<jupyter_code>a1=[4,5,8,1,0,9]
a1.reverse()
a1<jupyter_output><empty_output><jupyter_text>- 3![](../Photo/123.png)<jupyter_code>i=1
a1=input('enter inters between 1and 100:')
a1=a1.split(',')
a1.sort()
print(a1)
a2={}
for i in a1:
    b1=a1.count(i)
    a2[i] = b1
print(a2)
#     print(str(i)+'occurs '+str(b1)+'times')  
for i in a2.items():
        print(i)
        print(i[0]+'occurs '+str(i[1])+'times')<jupyter_output>enter inters between 1and 100:2,2,3,3,4
['2', '2', '3', '3', '4']
{'2': 2, '3': 2, '4': 1}
('2', 2)
2occurs 2times
('3', 2)
3occurs 2times
('4', 1)
4occurs 1times
{'fraction_non_alphanumeric': 0.2103080568720379, 'fraction_numerical': 0.07444707740916272, 'mean_word_length': 5.0731414868105515, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '269800', 'license': 'Apache-2.0', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2580, 'n_words': 451, 'path': '7.25.ipynb', 'repo_name': 'ggznmg/test', 'size': '5064'}