python读取TXT到数组及列表去重后按原来顺序排序的方法

yipeiwu_com5年前Python基础

本文实例讲述了python读取TXT到数组及列表去重后按原来顺序排序的方法。分享给大家供大家参考。具体如下:

####################################################################
# python 读取TXT到数组  列表去重,不打乱原来的顺序
# 刚学写的不好请大家见谅
####################################################################
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 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导入数组
  #passlist = list(set(passlist))  #python 列表去重
  global list_passwed #列表去重,不打乱原来的顺序
  list_passwed=[]
  for i in passlist:
    if i not in list_passwed:
      list_passwed.append(i)
######################################  遍历数组组合出 密码
  I1 = 0 #得到list的第一个元素
  while I1 < len(list_passwed):
    print "WWWWWWWWWWW",I1
    if I1==len(list_passwed):
      break #退出循环
    I2 = 0 #得到list的第一个元素
    while I2 < len(list_passwed):
      print "1111:",list_passwed[I1],"2222:",list_passwed[I2]
      I2 = I2 + 1 #二层
    I1 = I1 + 1  #一层

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python使用mysql数据库示例代码

一,安装mysql 如果是windows 用户,mysql 的安装非常简单,直接下载安装文件,双击安装文件一步一步进行操作即可。 Linux 下的安装可能会更加简单,除了下载安装包进...

Python函数的周期性执行实现方法

本文实例讲述了Python函数的周期性执行实现方法。分享给大家供大家参考,具体如下: 需要用到python的sched模块: #coding=utf-8 import time,sc...

Python操作列表之List.insert()方法的使用

 insert()方法插入对象obj到列表的偏移量索引。 语法 以下是insert()方法的语法: list.insert(index, obj) 参数 &nb...

Python实现扩展内置类型的方法分析

本文实例讲述了Python实现扩展内置类型的方法。分享给大家供大家参考,具体如下: 简介 除了实现新的类型的对象方式外,有时我们也可以通过扩展Python内置类型,从而支持其它类型的数据...

探究Python多进程编程下线程之间变量的共享问题

 1、问题: 群中有同学贴了如下一段代码,问为何 list 最后打印的是空值?   from multiprocessing import Process, M...