Python reads the TXT file to the array and the list is de-duplicated and then sorted in the original order, pythontxt

Source: Internet
Author: User
Tags python list

Python reads the TXT file to the array and the list is de-duplicated and then sorted in the original order, pythontxt

This example describes how to sort TXT files in the original order after deduplication from the array and list. Share it with you for your reference. The details are as follows:

######################################## ########################### Python reads TXT files to the array list for deduplication, don't disrupt the original sequence # Sorry for the hard work you just learned ########################### ######################################## # def open_txt (): # Open the TXT text and write the array try: infile = file('admin.txt ', 'R') xxx = file('admin.txt', 'R') for xxx_line in xxx. readlines (): passlist. append (xxx_line) xxx. close () Cancel T: return 0def list_del (): # clear list try: I = 0 # Get the first element of list while I <len (passlist ): del passlist [I] del list_passwed [I] Doesn't: return 0 ###################################### global passlist # declare the global variable passlist = [] # User Name: anonymous password is blank www_cj (www) # domain name dismantling open_txt () # TXT import array # passlist = list (set (passlist) # python list deduplication global list_passwed # list deduplication, do not disrupt the original sequence list_passwed = [] for I in passlist: if I not in list_passwed: list_passwed.append (I) ###################################### traverse an array combine the password I1 = 0 # Get the first element of the list while I1 <len (list_passwed): print "WWWWWWWWWWW", I1 if I1 = len (list_passwed): break # exit loop I2 = 0 # Get the first element of list while I2 <len (list_passwed ): print "1111:", list_passwed [I1], "2222:", list_passwed [I2] I2 = I2 + 1 # Layer 2 I1 = I1 + 1 # Layer 1

I hope this article will help you with Python programming.

Related Article

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.