#!/usr/bin/env python # encoding: utf-8 #字典去重小代码 import sys import os import platform try: pass except: print '''you have something wrong this is a simple jiaoben ''' sys.exit() why = 'why.txt' for i in xrange(len(sys.argv)): if(i>=1): other = sys.ar…
一.方法1 代码如下 复制代码 ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] for id in ids: if id not in news_ids: news_ids.append(id) print news_ids 思路看起来比较清晰简单 ,也可以保持之前的排列顺序. 二.方法2 通过set方法进行处理 代码如下 复制代码 ids = [1,4,3,3,4,2,3,4,5,6,1] ids = list(set(ids…
一.方法1 代码如下 复制代码 ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] for id in ids: if id not in news_ids: news_ids.append(id) print news_ids 思路看起来比较清晰简单 ,也可以保持之前的排列顺序. 二.方法2 通过set方法进行处理 代码如下 复制代码 ids = [1,4,3,3,4,2,3,4,5,6,1] ids = list(set(ids…
今天实习的web大表哥说帮我看环境不过前提是要我帮他写个python合并列表的demo, 大概思路就是利用zip库进行keys和values的遍历,然后在输出就行 key1={'name1':'小明','name2':'小红'} key2={'小明':'[men,20]','小红':'[women,30]'} for k,v in zip(key1.values(),key1.keys()): for i, j in zip(key2.values(), key2.keys()): if k =…
1.图像转换为矩阵 matrix = numpy.asarray(image) Help on function asarray in module numpy.core.numeric: asarray(a, dtype=None, order=None) Convert the input to an array. Parameters ---------- a : array_like Input data, in any form that can be converted to an…
1. 列表去重 li = [] for item in my_list: if item not in li: li.append(item) 2.集合去重 list(set(my_list)) 3.字典去重 dict1 = dict.fromkeys(my_list, '') li = dict1.keys…