<jupyter_start><jupyter_text>列表List- 一个列表可以储存任意大小的数据集合，你可以理解为他是一个容器  先来一个例子爽一爽![](../Photo/115.png)<jupyter_code>print('jieguo',count)NUMBER_OF_ELEMENTS=5
numbers = []
sum = 0
for i in range(NUMBER_OF_ELEMENTS):
    values = eval(input('>>'))
    numbers.append(value)
    sum+=value
    
average = sum / NUMBER_OF_ELEMENTS
count = 0
for i in range(NUMBER_OF_ELEMENTS):
    if numbers[i]>average:
        count+=1
print('average',average)<jupyter_output>>>3<jupyter_text>创建一个列表- a = [1,2,3,4,5]<jupyter_code>a=[1,2,3,4,5,6]
a[-4:-2]
a[0:-1:2]
#列表与数字相乘---->变2倍<jupyter_output><empty_output><jupyter_text>列表的一般操作![](../Photo/116.png)  列表索引操作- Mylist[index]- 正序索引，逆序索引- 列表一定注意越界- ![](../Photo/117.png)  列表切片操作- Mylist[start:end]- 正序切片，逆序切片  列表 +、*、in 、not in  使用for循环遍历元素- for 循环可以遍历一切可迭代元素  EP：- 使用while 循环遍历列表  列表的比较- \>,=,<=,==,!=  列表生成式[x for x in range(10)]<jupyter_code>a=[x for x in range(10)]
a
b=(x for x in range(10))  #列表生成器
b
b=(x for x in range(10))  #列表生成器
next(b)#用一个生成一个<jupyter_output><empty_output><jupyter_text>列表的方法![](../Photo/118.png)<jupyter_code>a=[1,2,3,4]
a.append([10,20])
a<jupyter_output><empty_output><jupyter_text>将字符串分割成列表- split  按照自定义的内容拆分  EP:![](../Photo/119.png)![](../Photo/120.png)<jupyter_code>ls1=[1,43]
ls2=ls1
ls1[0]=100
print(ls1,ls2)
ls1=[1,43]
ls2=ls1
ls2[0]=50
print(ls1,ls2)
ls1=[1,43]
ls2=ls1.copy()
ls1[0]=100
print(ls1,ls2)
#random.shuffle(lst)    随机打乱列表顺序
import random
a=[1,2,3,4,5]
random.shuffle(a)
a
a.pop()    #默认移除最后一个
a.pop(0)
a      #还剩除0位置和最后一个
c=[['q',3],['w',2],['e',6]]
c.sort() #按名字排序
c
c.sort(key=lambda x:x[1],reverse=True)  #按数字排序
c
sorted(c,key=lambda x:x[1],reverse=True)
c4 = [['Joker',['shuaishuai',0],19],['lala',['meimei',-1],80],['caoyuan',['yuanyuan',8],5]]
sorted(c4,key=lambda x:x[1][1])<jupyter_output><empty_output><jupyter_text>列表的复制- copy 浅复制- deepcopy import copy  深复制- http://www.pythontutor.com/visualize.htmlmode=edit<jupyter_code>#多级拷贝---->用深拷贝<jupyter_output><empty_output><jupyter_text>列表排序- sort- sorted- 列表的多级排序    - 匿名函数  EP：- 手动排序该列表[5,3,8,0,17]，以升序或者降序<jupyter_code>a=[5,3,8,0,17]
a.sort()
a
a.reverse()
a<jupyter_output><empty_output><jupyter_text>- 1![](../Photo/121.png)<jupyter_code>a = input('Enter scores:')
grede = a.split(' ')
best = int(max(grede))
for i in range(len(grede)):
    if int(grede[i]) >= best - 10:
        print('Student 0 score is',grede[i],'and grande is A')
    elif int(grede[i]) >= best -20:
        print('Student 0 score is',grede[i],'and grande is B')
    elif int(grede[i]) >= best -30:
        print('Student 0 score is',grede[i],'and grande is C')
    elif int(grede[i]) >= best -40:
        print('Student 0 score is',grede[i],'and grande is D')
    else:
        print('Student 0 score is',grede[i],'and grande is F')<jupyter_output>Enter scores:40 55 70 58
Student 0 score is 40 and grande is C
Student 0 score is 55 and grande is B
Student 0 score is 70 and grande is A
Student 0 score is 58 and grande is B<jupyter_text>- 2![](../Photo/122.png)<jupyter_code>a=[1,2,3,4,5,6]
print(a)
a.reverse()
print(a)<jupyter_output>[1, 2, 3, 4, 5, 6]
[6, 5, 4, 3, 2, 1]<jupyter_text>- 3![](../Photo/123.png)<jupyter_code>a = input('>>')
b = a.split()
for i in range(len(b)):
    print(b[i],':',b.count(b[i]))<jupyter_output>>>1 1 1 2 2 3
1 : 3
1 : 3
1 : 3
2 : 2
2 : 2
3 : 1<jupyter_text>- 4![](../Photo/124.png)<jupyter_code>a = input('>>')
b = a.split()
n=len(b)
s=0
for i in range(n):
    s+=int(b[i])
    ave=s/n
print(ave)<jupyter_output>>>2 4 6
4.0<jupyter_text>- 5![](../Photo/125.png)<jupyter_code>import random
a = [random.choice([0,1,2,3,4,5,6,7,8,9]) for n in range(1000)]
b = [(i,a.count(i)) for i in set(a)]
print(b)<jupyter_output>[(0, 103), (1, 95), (2, 102), (3, 88), (4, 113), (5, 106), (6, 85), (7, 121), (8, 90), (9, 97)]<jupyter_text>- 6![](../Photo/126.png)<jupyter_code>a = input('>>')
b = a.split()
c = int(min(b))
for i in range(len(b)):
    if int(b[i])==c:
        print(c,i)<jupyter_output>>>4 2 6
2 1<jupyter_text>- 7![](../Photo/127.png)![](../Photo/128.png)<jupyter_code>import random
a = input('>>')
b = a.split()
random.shuffle(b)
print(b)<jupyter_output>>>1 2 3 4
['1', '3', '4', '2']<jupyter_text>- 8![](../Photo/129.png)<jupyter_code>def f(b): 
    c=list(set(b)) 
    print(c)
a = input('>>')
b = a.split()
f(b)
a=[1,2,3,4,4,5,6,7] 
b=a.copy()  
c=list(set(b))   
for i in c:
    if i in b:
        a.remove(i) 
print(a)
a=[1,2,3,4,4,5,5,6,7,8] 
c=list(set(a)) 
print(c)<jupyter_output>[1, 2, 3, 4, 5, 6, 7, 8]
{'fraction_non_alphanumeric': 0.22971761541909458, 'fraction_numerical': 0.07350963693411026, 'mean_word_length': 4.895640686922061, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 82, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '555292', 'license': 'Apache-2.0', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2304, 'n_words': 392, 'path': '7.25.ipynb', 'repo_name': 'Zhy411/zhy', 'size': '4462'}