python讀取TXT到數(shù)組及列表去重后按原來順序排序的方法
更新時間:2015年06月26日 17:41:46 作者:寫代碼沒錢途
這篇文章主要介紹了python讀取TXT到數(shù)組及列表去重后按原來順序排序的方法,涉及Python操作txt文件、列表去重及排序的相關技巧,需要的朋友可以參考下
本文實例講述了python讀取TXT到數(shù)組及列表去重后按原來順序排序的方法。分享給大家供大家參考。具體如下:
####################################################################
# python 讀取TXT到數(shù)組 列表去重,不打亂原來的順序
# 剛學寫的不好請大家見諒
####################################################################
def open_txt(): #打開TXT文本寫入數(shù)組
try:
infile = file('admin.txt', 'r')
xxx = file('admin.txt', 'r')
for xxx_line in xxx.readlines():
passlist.append(xxx_line)
xxx.close()
except:
return 0
def list_del(): #清空list列表
try:
i = 0 #得到list的第一個元素
while i < len(passlist):
del passlist[i]
del list_passwed[i]
except:
return 0
######################################
global passlist #聲明全局變量
passlist = [] #用戶名:anonymous 密碼為空
www_cj(www) #域名拆解
open_txt() #TXT導入數(shù)組
#passlist = list(set(passlist)) #python 列表去重
global list_passwed #列表去重,不打亂原來的順序
list_passwed=[]
for i in passlist:
if i not in list_passwed:
list_passwed.append(i)
###################################### 遍歷數(shù)組組合出 密碼
I1 = 0 #得到list的第一個元素
while I1 < len(list_passwed):
print "WWWWWWWWWWW",I1
if I1==len(list_passwed):
break #退出循環(huán)
I2 = 0 #得到list的第一個元素
while I2 < len(list_passwed):
print "1111:",list_passwed[I1],"2222:",list_passwed[I2]
I2 = I2 + 1 #二層
I1 = I1 + 1 #一層
希望本文所述對大家的Python程序設計有所幫助。
相關文章
淺談Keras的Sequential與PyTorch的Sequential的區(qū)別
這篇文章主要介紹了淺談Keras的Sequential與PyTorch的Sequential的區(qū)別,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06
已安裝Pytorch卻提示no?moudle?named?'torch'(沒有名稱為torch
這篇文章主要給大家介紹了關于已安裝Pytorch卻提示no?moudle?named?'torch'(沒有名稱為torch的模塊)的相關資料,當提示"No module named 'torch'"時,可能是由于安裝的Pytorch版本與當前環(huán)境不匹配導致的,需要的朋友可以參考下2023-11-11
用Python實現(xiàn)數(shù)據(jù)篩選與匹配實例
大家好,本篇文章主要講的是用Python實現(xiàn)數(shù)據(jù)篩選與匹配實例,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下2022-02-02
如何利用Python+OpenCV實現(xiàn)簡易圖像邊緣輪廓檢測(零基礎)
輪廓是形狀分析和物體檢測和識別的有用工具,下面這篇文章主要給大家介紹了關于如何利用Python+OpenCV實現(xiàn)簡易圖像邊緣輪廓檢測(零基礎)的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-05-05

