Python reads txt to array and lists the method of sorting in the original order

Source: Internet
Author: User
The examples in this article describe how Python reads txt to arrays and lists to be sorted in the original order. Share to everyone for your reference. Specific as follows:

##################################################################### python read txt to array list to go heavy, do not disturb the original order # just learn to write bad please forgive US # # ################################################################# #def open_txt (): #打开TXT文本写入数组 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 0def List_del (): #清空list列表 try:i = 0 #得到list的第一个元素 while I < Len (passlist): de L Passlist[i] del List_passwed[i] except:return 0###################################### global passlist #声明全局变 Volume passlist = [] #用户名: Anonymous password is empty www_cj (www) #域名拆解 open_txt () #TXT导入数组 #passlist = List (set (passlist)) #python column Table to go to the global list_passwed #列表去重, do not disrupt the original order list_passwed=[] for i in the passlist:if I not in list_passwed:list_passwe D.append (i) ###################################### traversal array combination out password I1 = 0 #得到list的第一个元素 while I1 < Len (list_passwed): P Rint "Wwwwwwwwwww", I1 if I1==leN (list_passwed): break #退出循环 I2 = 0 #得到list的第一个元素 while I2 < Len (list_passwed): print "1111:", List_pass WED[I1], "2222:", list_passwed[i2] I2 = I2 + 1 #二层 I1 = I1 + 1 #一层

Hopefully this article will help you with Python programming.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.