Board logo

標題: 串列 (二) [打印本頁]

作者: 陳品肇    時間: 2020-2-2 09:02     標題: 串列 (二)

假設有一串列其內容如下:
list=[12,-3,-50,32,25,11]

試以sort()、reverse()、len()、pop()、append()、insert()等函式,完成如下操作:
[attach]8362[/attach]
  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 陳頡鴻    時間: 2020-2-2 11:15

  1. list1=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list1.sort();
  4. print("排序後(遞增):",list1)
  5. list.reverse();
  6. print("排序後(遞減):",list1)
  7. print("元素數量:",len(list1))
  8. list1.pop()
  9. print("pop掉一元素",list1)
  10. list.append(-20)
  11. print("append一元素",list1)
  12. list1.insert(4,0)
  13. print("insert一元素",list1)
複製代碼

作者: 陳沛頤    時間: 2020-2-2 11:16

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 李穎俊    時間: 2020-2-2 11:17

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 林奇陞    時間: 2020-2-2 11:17

[code][/code]list=[12,-3,-50,32,25,11]
print("排序前:",list)
list.sort();
print("排序後(遞增):",list)
list.reverse();
print("排序後(遞減):",list)
print("元素數量:",len(list))
list.pop()
print("pop掉一元素",list)
list.append(-20)
print("append一元素",list)
list.insert(4,0)
print("insert一元素",list)# -*- coding: utf-8 -*-
作者: 黃紹綸    時間: 2020-2-2 11:19

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 林依玟    時間: 2020-2-2 11:20

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 曾柏忻    時間: 2020-2-2 11:20

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 黃紹恩    時間: 2020-2-2 11:22

  1. list=[11,-4,-25,50,1,15]

  2. print("排序前:",list)

  3. list.sort()

  4. print("排序後(遞增):",list)

  5. list.reverse()

  6. print("排序後(遞減):",list)

  7. print("元素數量:",len(list))

  8. list.pop()

  9. print("pop掉一元素",list)

  10. list.append(-20)

  11. print("append一元素",list)

  12. list.insert(4,0)

  13. print("insert一元素",list)

  14. list.clear()

  15. print(list)
複製代碼

作者: 曾顗文    時間: 2020-2-2 11:22

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 張鈞堯    時間: 2020-2-2 11:22

  1. a=[1,2,3,4,5,6,"a","b","c","d"]
  2. print(type(a[4]))
  3. print(type(a[6]))
  4. print(len(a))
  5. a.append("e")
  6. print(a)
  7. a.insert(11,"f")
  8. print(a)
  9. a.pop(0)
  10. print(a)
  11. a.remove("f")
  12. print(a)
  13. b=[5,0,1,4,6,1]
  14. b.sort()
  15. print(b)
  16. b.reverse()
  17. print(b)
複製代碼

作者: 許雅棟    時間: 2020-2-2 11:23

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 黃柏叡    時間: 2020-2-2 11:24

  1. list=[12,-3,-50,32,25,11]
  2. print("前:",list)
  3. list.sort();
  4. print("遞增:",list)
  5. list.reverse();
  6. print("遞減:",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("刪除一元素",list)
  10. list.append(-20)
  11. print("增加一元素",list)#加到最後
  12. list.insert(4,0)
  13. print("加入一元素",list)#加到指定位子
複製代碼

作者: 潘堉恩    時間: 2020-2-2 11:24

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 傅品翰    時間: 2020-2-2 11:26

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)   
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 傅英哲    時間: 2020-2-2 11:29

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

作者: 張鈞堯    時間: 2020-2-2 13:43

  1. a=[]
  2. for i in range(1,100,2):
  3.     a.insert(0,i)
  4. for b in a:
  5.     print(b)
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2