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

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

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

本文實(shí)例總結(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

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

相關(guān)文章

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

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

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

    Python GUI編程 文本彈窗的實(shí)例

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

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

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

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

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

    Pycharm添加虛擬解釋器報(bào)錯(cuò)問題解決方案

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

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

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

    淺談Python之Django(二)

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

    基于PyQt5完成的PDF拆分功能

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

    Python 使用openpyxl處理Excel文件詳情

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

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

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

最新評(píng)論

无锡市| 怀集县| 射阳县| 理塘县| 乾安县| 会同县| 鹤峰县| 阳高县| 剑川县| 逊克县| 太保市| 永清县| 嘉义市| 黄龙县| 济阳县| 鹿邑县| 浮山县| 合川市| 塘沽区| 常德市| 吴堡县| 淮南市| 西林县| 桐庐县| 固安县| 黑龙江省| 保德县| 荣昌县| 鄂温| 太湖县| 保康县| 日土县| 札达县| 保定市| 赤峰市| 郯城县| 塔城市| 贵德县| 桐柏县| 旺苍县| 房产|