This article mainly introduces how to sort TXT files, list de-duplication, and sorting in the original order after reading the txt files to the array and list in python, for more information, see the example in this article. 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.