<jupyter_start><jupyter_text>列表List- 一个列表可以储存任意大小的数据集合，你可以理解为他是一个容器  先来一个例子爽一爽![](../Photo/115.png)  创建一个列表- a = [1,2,3,4,5]  列表的一般操作![](../Photo/116.png)  列表索引操作- Mylist[index]- 正序索引，逆序索引- 列表一定注意越界- ![](../Photo/117.png)  列表切片操作- Mylist[start:end]- 正序切片，逆序切片  列表 +、*、in 、not in  使用for循环遍历元素- for 循环可以遍历一切可迭代元素  EP：- 使用while 循环遍历列表  列表的比较- \>,=,<=,==,!=<jupyter_code>##列表生成式
[x for x in range(10) if x % 2 == 0]
[x for x in range(10)]
import random
[random.randint() for i in range(10)]
"""
用for循环，索引,冒泡循环
"""
b = [4,3,2,1]
length = len(b)
for i in range(length - 1):
    for j in range(length - i - 1):#- 1 是锁定最大值
        if b[j] > b[j + 1]:
            b[j],b[j + 1] = b[j + 1],b[j]
print(b)
a = [1,2,1,3,4]
a.count(1)
a = [1,2,3]
b = [100,200]
a.extend(b)
a
c = [1,1,2,2,3]
c.index(2)
c = [1,2,3,4]
c.insert(0,100)
c
#移除
a = [1,2,3]
a.pop(1)
a
"""
所有的奇数位前插入100
"""
c = [1,2,3,4,5]
for i in range(0,len(c) + 3,3):
    c.insert(i,100)
c
"""
所有的奇数位前插入100,随便顺序
"""
c = [1,4,5,3,7]
for i in range(len(c)):
    if i % 2 == 0:
        c.insert(0,100)
    if j % 2 == 0:
        c.insert(0,100)
    else:
        print()
c
d = [1,2,3,4]
d.remove(3)
d
d = [1,2,3,4]
d.reverse()
d
#索引倒序：[::-1]
d = [1,5,7,8,6]
d.sort(reverse = True)
d<jupyter_output><empty_output><jupyter_text>将字符串分割成列表- split  按照自定义的内容拆分<jupyter_code>a = "a b c d"
a.split(" ")
a = "a!b!c!d"
a.split("!")
a = "ab cd"
a.split(" ")
a = "a b c d"
a.split(" ",2)<jupyter_output><empty_output><jupyter_text>EP:![](../Photo/119.png)![](../Photo/120.png)<jupyter_code>#随机打乱

lst = [30,1,2,1,0]
random.shuffle(lst)
lst
lst = [30,1,2,1,0]
lst.reverse()
lst
lst = [30,1,2,1,0]
lst.pop()
lst = [30,1,2,1,0]
lst.pop(1)
lst
lst = [30,1,2,1,0]
lst.remove(1)
lst
lst = [30,1,2,1,0]
lst.extend([1,43])
lst
lst = [30,1,2,1,0]
lst.insert(2,43)
lst
lst = [30,1,2,1,0]
lst.append(40)
lst<jupyter_output><empty_output><jupyter_text>列表的复制- copy 浅复制- deepcopy import copy  深复制- http://www.pythontutor.com/visualize.htmlmode=edit<jupyter_code>c = [1,2,3]
d = c
d.copy()
c = [1,2,3]
d = c.copy()
d
import copy
a = [1,2,3,[100,200]]
b = copy.deepcopy(a)
b
a[3][0] = 1000
a<jupyter_output><empty_output><jupyter_text>列表排序- sort- sorted- 列表的多级排序    - 匿名函数<jupyter_code>c = [1,3,4]
c.sort(reverse = True)
c
(lambda x:print(x**2))(100)#匿名函数

#******考试必考
c = [["xuexueting",100],["ZWJ",90],["JCX",94],["CH",89]]
c.sort(key = lambda x:x[1])
c
c = [[["xuexueting",100,[50,70]]
     ,["ZWJ",90,[80,50]]
     ,["JCX",94,[70,60]]
     ,["CH",89,[100,100]]
c.sort(key = lambda x:x[2][0],reverse)
c<jupyter_output><empty_output><jupyter_text>EP：- 手动排序该列表[5,3,8,0,17]，以升序或者降序 - 1![](../Photo/121.png)<jupyter_code>score = input("请输入成绩")
def chengji():
    if i >= best - 10:
        print("A")
    if j >= best - 20:
        print("B")
    if m >= best - 30:
        print("C")
    if n >= best - 40:
        print("D")
    else:
        print("F")
chengji()<jupyter_output><empty_output><jupyter_text>- 2![](../Photo/122.png)<jupyter_code>old_list = [4,8,5,6,7,95,84,61,54]
print (old_list)
new_list = []
print('将列表逆序输出')
for i in range(len(old_list)):
    a = old_list.pop()
    new_list.append(a)
print (new_list)<jupyter_output>[4, 8, 5, 6, 7, 95, 84, 61, 54]
将列表逆序输出
[54, 61, 84, 95, 7, 6, 5, 8, 4]<jupyter_text>- 3![](../Photo/123.png)<jupyter_code>a = [2,5,6,5,4,3,23,43,2]
a.count(2)
a = [2,5,6,5,4,3,23,43,2]
a.count(3)
a = [2,5,6,5,4,3,23,43,2]
a.count(4)
a = [2,5,6,5,4,3,23,43,2]
a.count(5)
a = [2,5,6,5,4,3,23,43,2]
a.count(6)
a = [2,5,6,5,4,3,23,43,2]
a.count(23)
a = [2,5,6,5,4,3,23,43,2]
a.count(43)<jupyter_output><empty_output><jupyter_text>- 4![](../Photo/124.png)<jupyter_code>def index():<jupyter_output><empty_output><jupyter_text>- 5![](../Photo/125.png) - 6![](../Photo/126.png)<jupyter_code>def index0fSmallestElement():
    lst =<jupyter_output><empty_output><jupyter_text>- 7![](../Photo/127.png)![](../Photo/128.png)<jupyter_code>def shuffle(lst):
    random.shuffle(lst)<jupyter_output><empty_output><jupyter_text>- 8![](../Photo/129.png)<jupyter_code>def eliminateDuplicates(c):
    c = [1,2,3,1,6,4,5]
    for i in c:
        if i not in c:
            c.append(i)
    return c
eliminateDuplicates(2)<jupyter_output><empty_output><jupyter_text>- 9![](../Photo/130.png)<jupyter_code>liebiao = input("输入列表")
def isSorted(lst):
    if i < i +1:
        print("排好序")
    else:
        print("没排好序")<jupyter_output>输入列表5<jupyter_text>- 10![](../Photo/131.png)<jupyter_code>def bubbleSort(arr):
    n = len(arr) # 遍历所有数组元素 
    for i in range(n): 
        for j in range(0, n - i - 1):
            if arr[j] > arr[j + 1] : 
                arr[j], arr[j + 1] = arr[j + 1], arr[j] 
arr = [78,58,64,97,45,15,45,32,46] 
bubbleSort(arr)
print ("排序后的数组:")
for i in range(len(arr)):
    print ("%d" %arr[i]),<jupyter_output>排序后的数组:
15
32
45
45
46
58
64
78
97<jupyter_text>- 11![](../Photo/132.png) - 12![](../Photo/133.png)<jupyter_code>def isConsecutiveFour(values):<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.24114193156509414, 'fraction_numerical': 0.09941283660660052, 'mean_word_length': 4.061475409836065, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 65, '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': '518191', 'license': 'Apache-2.0', 'n_tokens_mistral': 2916, 'n_tokens_neox': 2708, 'n_words': 414, 'path': '7.25.ipynb', 'repo_name': 'motuoluolalalal/mysql', 'size': '4939'}