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

python選擇排序算法實例總結(jié)

 更新時間:2015年07月01日 11:17:18   作者:pythoner  
這篇文章主要介紹了python選擇排序算法,以三個實例以不同方法分析了Python實現(xiàn)選擇排序的相關技巧,需要的朋友可以參考下

本文實例總結(jié)了python選擇排序算法。分享給大家供大家參考。具體如下:

代碼1:

def ssort(V):
#V is the list to be sorted 
 j = 0
 #j is the "current" ordered position, starting with the first one in the list 
 while j != len(V):
 #this is the replacing that ends when it reaches the end of the list 
   for i in range(j, len(V)):
   #here it replaces the minor value that it finds with j position 
     if V[i] < V[j]:
     #but it does it for every value minor than position j 
       V[j],V[i] = V[i],V[j] 
   j = j+1
   #and here's the addiction that limits the verification to only the next values 
 return V 

代碼2:

def selection_sort(list): 
  l=list[:]
  # create a copy of the list 
  sorted=[]
  # this new list will hold the results 
  while len(l):
  # while there are elements to sort... 
    lowest=l[0]
    # create a variable to identify lowest 
    for x in l:
    # and check every item in the list... 
      if x<lowest:
      # to see if it might be lower. 
        lowest=x 
    sorted.append(lowest)
    # add the lowest one to the new list 
    l.remove(lowest)
    # and delete it from the old one 
  return sorted

代碼3

a=input("Enter the length of the list :")
# too ask the user length of the list 
l=[]
# take a emty list 
for g in range (a):
# for append the values from user 
  b=input("Enter the element :")
  # to ask the user to give list values 
  l.append(b)
  # to append a values in a empty list l 
print "The given eliments list is",l 
for i in range (len(l)):
# to repeat the loop take length of l 
  index=i
  # to store the values i in string index 
  num=l[i]
  # to take first value in list and store in num 
  for j in range(i+1,len(l)):
  # to find out the small value in a list read all values 
    if num>l[j]:
    # to compare two values which store in num and list 
      index=j
      # to store the small value of the loop j in index 
      num=l[j]
      # to store small charecter are value in num 
  tem=l[i]
  # to swap the list take the temparary list stor list vlaues 
  l[i]=l[index]
  # to take first value as another 
  l[index]=tem 
print "After the swping the list by selection sort is",l

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

相關文章

  • Python中numpy數(shù)組真值判斷的實現(xiàn)

    Python中numpy數(shù)組真值判斷的實現(xiàn)

    在Python編程中,經(jīng)常需要對數(shù)組進行真值判斷,本文就來介紹一下Python中numpy數(shù)組真值判斷的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2023-09-09
  • Python GUI編程 文本彈窗的實例

    Python GUI編程 文本彈窗的實例

    今天小編就為大家分享一篇Python GUI編程 文本彈窗的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • 基于Python實現(xiàn)的戀愛對話小程序詳解

    基于Python實現(xiàn)的戀愛對話小程序詳解

    這篇文章主要介紹了基于Python制作一個戀愛對話小程序,文章詳細介紹了小程序的實現(xiàn)過程,感興趣的小伙伴可以跟隨小編一起學習學習
    2022-01-01
  • Pandas實現(xiàn)Excel文件讀取,增刪,打開,保存操作

    Pandas實現(xiàn)Excel文件讀取,增刪,打開,保存操作

    Pandas?是一種基于?NumPy?的開源數(shù)據(jù)分析工具,用于處理和分析大量數(shù)據(jù)。本文將通過Pandas實現(xiàn)對Excel文件進行讀取、增刪、打開、保存等操作,需要的可以參考一下
    2023-04-04
  • Pycharm添加虛擬解釋器報錯問題解決方案

    Pycharm添加虛擬解釋器報錯問題解決方案

    這篇文章主要介紹了Pycharm添加虛擬解釋器報錯問題解決方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-10-10
  • django有哪些好處和優(yōu)點

    django有哪些好處和優(yōu)點

    在本篇內(nèi)容里小編給大家整理的是一篇關于django有哪些好處和優(yōu)點的相關內(nèi)容,有需要的朋友們可以參考下。
    2020-09-09
  • 淺談Python之Django(二)

    淺談Python之Django(二)

    這篇文章主要介紹了Python3中的Django,小編覺得這篇文章寫的還不錯,需要的朋友們下面隨著小編來一起學習學習吧,希望能夠給你帶來幫助
    2021-10-10
  • 基于PyQt5完成的PDF拆分功能

    基于PyQt5完成的PDF拆分功能

    這篇文章主要介紹了基于PyQt5完成的PDF拆分功能,本文介紹的pdf拆分功能還有一些待完善地方,例如可增加預覽功能,實現(xiàn)每頁預覽,以及如何實現(xiàn)多條件拆分,需要的朋友可以參考下
    2022-06-06
  • Python 使用openpyxl處理Excel文件詳情

    Python 使用openpyxl處理Excel文件詳情

    這篇文章主要介紹了Python 使用openpyxl處理Excel文件詳情,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-08-08
  • Python實現(xiàn)給文件添加內(nèi)容及得到文件信息的方法

    Python實現(xiàn)給文件添加內(nèi)容及得到文件信息的方法

    這篇文章主要介紹了Python實現(xiàn)給文件添加內(nèi)容及得到文件信息的方法,可實現(xiàn)從文件開頭添加內(nèi)容的功能,需要的朋友可以參考下
    2015-05-05

最新評論

南涧| 邛崃市| 恭城| 祁东县| 体育| 通许县| 玉门市| 颍上县| 丁青县| 宁德市| 娄底市| 郴州市| 独山县| 石屏县| 乐都县| 甘南县| 张家港市| 定兴县| 家居| 无极县| 伊宁县| 广丰县| 尤溪县| 丰镇市| 从江县| 翁源县| 分宜县| 邳州市| 高台县| 高州市| 安多县| 当阳市| 延庆县| 连州市| 贡嘎县| 彰化市| 郸城县| 澜沧| 恩施市| 双流县| 普兰县|