Board logo

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

作者: tonyh    時間: 2020-7-28 10:33     標題: 串列 (二)

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

試以sort()、reverse()、len()、pop()、append()、insert()等函式,完成如下操作:

  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-7-28 10:42

  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-7-28 10:42

  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-7-28 10:45

  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-7-28 10:45

  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-7-28 10:48

  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-7-28 10:49

  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-7-28 10:49

  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-7-28 10:50

  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-7-28 10:50

  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-7-28 10:51

  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-7-28 10:52

  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-7-28 10:53

  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-7-28 10:53

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

作者: 陳星翰    時間: 2020-7-28 10:55

  1. list=[12,-3,-50,32,25,11]
  2. print("list:", list)
  3. list.sort();
  4. print("numbers(least to greatest):",list)
  5. list.reverse();
  6. print("numbers(greatest to smallest):",list)
  7. print("number of numbers:",len (list))
  8. list.pop()
  9. print("popped smalest number",list)
  10. list.append(-20)
  11. print("appended a number",list)
  12. list.insert(4,0)
  13. print("inserted numbers",list)
複製代碼

作者: 楊書華    時間: 2020-7-28 10:57

  1. list=[2004,6,22,2005,2,5]
  2. print("Unsorted: ", list)
  3. list.sort()
  4. print("From least to Greatest:", list)
  5. list.reverse()
  6. print("From Greatest to Least: ", list)
  7. print("Numer of Elements: ", len(list))
  8. list. pop(5)
  9. print("After Deleting one Element: ", list)
  10. list. pop(2)
  11. print("After Deleting two Elements: ", list)
  12. list. append(9)
  13. list.sort()
  14. print("After Adding a new Element: ", list)
  15. list. append(23)
  16. list.sort()
  17. print("After Adding two new Elements: ", list)
  18. list. pop(1)
  19. print("After Deleting one Element: ", list)
  20. list. pop(0)
  21. print("After Deleting two Elements: ", list)
  22. list.insert(0,3)
  23. print("After Adding a new Element: ", list)
  24. list.insert(1,4)
  25. list.sort()
  26. print("After Adding a new Element: ", list)
複製代碼

作者: 蔡旭隆    時間: 2020-7-28 10:59

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





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