Python 列表-List
来源:互联网 发布:网络在线课程 国外 编辑:程序博客网 时间:2024/05/21 18:41
大学计算机–Python算法实践
李金双、李凤云、张昱
列表
数据序列,存储多个数据的连续空间
下标从 0 开始,不可越界,可为负数(表示从后往前数)
a_list = [1, 'this', 'that', 3]b_list = list('hello')c_list = list(range(0, 10, 2))print(a_list[-1]) #输出 3for x in c_list: print(x)for i in range (len(b_list)): print(b_list[i])
顺序查找
aList = [3, 3, 8, 8, 9, 3, 9, 1, 8, 0]print("8 第一次出现的位置是第 %d 个" %(aList.index(8)+1))print(aList.index(8, 4, len(aList)) + 1) #从4到 len(aList)之间出现的第一个8的下标print(aList.count(3)) #3出现的次数
添加数据
array = [1, 3, 9, 12, 0]array[4] = 20array.append(26)array.extend([27, 28, 29])array.insert(2, 6)for i in range(len(array)): print(array[i], end = ' ')#1 3 6 9 12 20 26 27 28 29
删除数据
aList = [1, 9, 2, 7]aList.remove(2)for x in aList: print(x)#1 9 7
作业
grade = []for i in range(10): std_id = str(input('input student ID: ')) score = float(input('input his/her score: ')) grade.append([std_id, score])for i in range(len(grade)): print(grade[i][0], grade[i][1], sep = '\t')
grade = [[201,77],[202,82],[203,93],[204,87],[205,88],[206,91]]find = int(input())flag = 0for i in range(len(grade)): if grade[i][0] == find : print(grade[i][1]) flag = 1 breakif flag == 0 : print('not find')
阅读全文
0 0
- Python 列表(list)操作
- Python 列表(list)操作
- Python 列表(list)操作
- python之list列表
- python学习-列表(list)
- Python 列表(list)操作
- Python list 数据类型:列表
- python list列表操作
- Python 列表(list)操作
- Python 列表(list)操作
- python中的list列表
- Python 列表(list)操作
- Python List列表操作
- python之列表(list)
- Python列表list
- python之列表list
- Python列表(List)
- Python 列表 (List)
- Windows hardware lab Kit learn
- poj 2201 Cartesian Tree 笛卡尔树
- adb实用命令小结
- ubuntu16.04主题美化和软件推荐
- java多线程总结(三):线程的同步和通信
- Python 列表-List
- office2007+ java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
- 拦截AlertDialog点击消失
- protoc使用手册
- 逆向分析涉及的工具及OD快捷键
- 【51nod】-1305 Pairwise Sum and Divide(数学)
- 赚钱
- 机器学习数学基础001-矩阵及矩阵的基本表示
- JAVA | 47