最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python列表操作實例

 更新時間:2015年01月14日 14:30:56   投稿:shichen2014  
這篇文章主要介紹了python列表操作方法,實例分析了Python針對列表操作的插入、刪除等各種操作技巧,需要的朋友可以參考下

本文實例講述了python列表操作的方法。分享給大家供大家參考。

具體實現(xiàn)方法如下:

復制代碼 代碼如下:
class Node:
   """Single node in a data structure"""
 
   def __init__(self, data):
      """Node constructor"""
      
      self._data = data
      self._nextNode = None
    
   def __str__(self):
      """Node data representation"""
 
      return str(self._data)    
 
class List:
   """Linked list"""
 
   def __init__(self):
      """List constructor"""
 
      self._firstNode = None
      self._lastNode = None
 
   def __str__(self):
      """List string representation"""
 
      if self.isEmpty():
         return "empty"
 
      currentNode = self._firstNode
      output = []
 
      while currentNode is not None:
         output.append(str(currentNode._data))
         currentNode = currentNode._nextNode
 
      return " ".join(output)    
 
   def insertAtFront(self, value):
      """Insert node at front of list"""
 
      newNode = Node(value)
 
      if self.isEmpty():  # List is empty
         self._firstNode = self._lastNode = newNode
      else:   # List is not empty
         newNode._nextNode = self._firstNode
         self._firstNode = newNode
        
   def insertAtBack(self, value):
      """Insert node at back of list"""
 
      newNode = Node(value)
 
      if self.isEmpty():  # List is empty
         self._firstNode = self._lastNode = newNode
      else:  # List is not empty
         self._lastNode._nextNode = newNode
         self._lastNode = newNode
 
   def removeFromFront(self):
      """Delete node from front of list"""
 
      if self.isEmpty():  # raise exception on empty list
         raise IndexError, "remove from empty list"
 
      tempNode = self._firstNode
 
      if self._firstNode is self._lastNode:  # one node in list
         self._firstNode = self._lastNode = None
      else:
         self._firstNode = self._firstNode._nextNode
 
      return tempNode
 
   def removeFromBack(self):
      """Delete node from back of list"""
 
      if self.isEmpty():  # raise exception on empty list
         raise IndexError, "remove from empty list"
     
      tempNode = self._lastNode
 
      if self._firstNode is self._lastNode:  # one node in list
         self._firstNode = self._lastNode = None
      else:
         currentNode = self._firstNode
 
         # locate second-to-last node
         while currentNode._nextNode is not self._lastNode:
               currentNode = currentNode._nextNode
               
         currentNode._nextNode = None
         self._lastNode = currentNode
 
      return tempNode
    
   def isEmpty(self):
      """Returns true if List is empty"""
 
      return self._firstNode is None

希望本文所述對大家的Python程序設(shè)計有所幫助。

相關(guān)文章

  • Python騷操作之動態(tài)定義函數(shù)

    Python騷操作之動態(tài)定義函數(shù)

    這篇文章主要介紹了Python騷操作之動態(tài)定義函數(shù),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • Django將默認的SQLite更換為MySQL的實現(xiàn)

    Django將默認的SQLite更換為MySQL的實現(xiàn)

    今天小編就為大家分享一篇Django將默認的SQLite更換為MySQL的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • python pyqtgraph 保存圖片到本地的實例

    python pyqtgraph 保存圖片到本地的實例

    這篇文章主要介紹了python pyqtgraph 保存圖片到本地的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Python3實現(xiàn)的判斷回文鏈表算法示例

    Python3實現(xiàn)的判斷回文鏈表算法示例

    這篇文章主要介紹了Python3實現(xiàn)的判斷回文鏈表算法,結(jié)合實例形式分析了Python3針對鏈表是否為回文鏈表進行判斷的相關(guān)算法實現(xiàn)技巧,需要的朋友可以參考下
    2019-03-03
  • Python發(fā)送email的3種方法

    Python發(fā)送email的3種方法

    這篇文章主要介紹了Python發(fā)送email的3種方法,本文講解了使用登錄郵件服務器方法、調(diào)用sendmail命令、使用smtp服務來發(fā)送三種方法,需要的朋友可以參考下
    2015-04-04
  • python接口調(diào)用已訓練好的caffe模型測試分類方法

    python接口調(diào)用已訓練好的caffe模型測試分類方法

    今天小編就為大家分享一篇python接口調(diào)用已訓練好的caffe模型測試分類方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • python實現(xiàn)圖片批量剪切示例

    python實現(xiàn)圖片批量剪切示例

    這篇文章主要介紹了python實現(xiàn)圖片批量剪切示例,需要的朋友可以參考下
    2014-03-03
  • Python基于docker部署的Mysql備份查詢腳本

    Python基于docker部署的Mysql備份查詢腳本

    這篇文章主要來和大家分享Python基于docker部署的Mysql備份查詢的腳本,文中的示例代碼講解詳細,有需要的小伙伴可以跟隨小編一起了解下
    2024-04-04
  • python Airtest自動化測試工具的的使用

    python Airtest自動化測試工具的的使用

    本文主要介紹了python Airtest自動化測試工具的的使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • python讀取圖片顏色值并生成excel像素畫的方法實例

    python讀取圖片顏色值并生成excel像素畫的方法實例

    這篇文章主要給大家介紹了關(guān)于python讀取圖片顏色值并生成excel像素畫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-02-02

最新評論

新郑市| 祁阳县| 鹤峰县| 彰武县| 福清市| 咸宁市| 寻甸| 灌云县| 万年县| 光山县| 古丈县| 吴川市| 潢川县| 偃师市| 柏乡县| 大关县| 江孜县| 苍梧县| 济源市| 建德市| 枣强县| 西昌市| 平原县| 承德县| 晋宁县| 靖安县| 古交市| 榕江县| 涡阳县| 鄂温| 耒阳市| 陈巴尔虎旗| 澄迈县| 东丰县| 青川县| 长海县| 诸城市| 措美县| 嫩江县| 海阳市| 渑池县|