#coding=gbk
import os #operating system
import sys #system
import copy
from pprint import pprint #perfect print
from operator import attrgetter
a = [1, 2, 3, 4, 5]
b = [6, 7, 8, 9, 10]
#python使用引用计数
c = a
print c
#[1, 2, 3, 4, 5]
c[0] = -1
print c
#[-1, 2, 3, 4, 5]
print a
#[-1, 2, 3, 4, 5]
a[0] = 1
print c
#[1, 2, 3, 4, 5]
print a
#[1, 2, 3, 4, 5]
#打包zip函数:
for i,j in zip(a, b):
print i, j
#输出
#1 6
#2 7
#3 8
#4 9
#5 10
#字典dict:
d ={}
for i,j in zip(a, b):
d[i] = j #d[key] = value
pprint(d)
#{1: 6, 2: 7, 3: 8, 4: 9, 5: 10}
#python使用引用计数,使用深度copy
d[1233] = {11111111111:copy.deepcopy(d)}
pprint(d)
#{1: 6,
# 2: 7,
# 3: 8,
# 4: 9,
# 5: 10,
# 1233: {11111111111L: {1: 6, 2: 7, 3: 8, 4: 9, 5: 10}}}
#链表list:
print sum(a)#15
print len(a)#5
print [2 * x for x in a]#[2, 4, 6, 8, 10] 列表解析
print a+b #[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#string:
print "&".join([str(x) for x in a])#1&2&3&4&5
print "1&2&3&4&5".split("&")#['1', '2', '3', '4', '5']
print len("abc")#3
#文件
fileName = "test.py"
for line in file(fileName):
line = line.strip().split("\t")
#eval 函数,可以解析字符串形式的python数据
print type(eval("[1,2]"))#<type 'list'>
print type(eval("{1:2}"))#<type 'dict'>
#os
print os.listdir(".")#显示dir的所有项
print dir(os)#输出os module的所有方法
print help(os)#输出os模块的help doc string
#二级排序(基于python sort是稳定的排序)This wonderful property lets you build complex sorts in a series of sorting steps. For example, to sort the student data by descending grade and then ascending age, do the age sort first and then sort again using grade:
class student:
def __init__(self, a, g):
self.age = a
self.grade = g
def __str__(self):
return "age=%d,grade=%d"%(self.age, self.grade)
student_objects = [student(10, 2),student(3, 40)]
s = sorted(student_objects, key=attrgetter('age')) # sort on age key
sorted(s, key=attrgetter('grade'), reverse=True) # now sort on grape key, descending
print [str(x) for x in s]
sys.exit(0)
分享到:
相关推荐
org.python.pydev.feature-1_3_24.zip
一些有用的Python脚本
资源分类:Python库 所属语言:Python 资源全名:featuretools-0.14.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。 资源全名:rpi_featureSelection_python_tools-2.0.16.tar.gz
资源分类:Python库 所属语言:Python 资源全名:feature_flags_client-1.0.13.dev1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。资源全名:feature_mapper-0.1.10.tar.gz
Python的一些图鉴
一些Python示例
Python做一些ascii艺术品
Python Tips 一些初学者到中级用户的Python技巧
关于 Python 的一些小工具
基于python的一些项目基于python的一些项目基于python的一些项目基于python的一些项目基于python的一些项目
一些PYTHON常用库 一些PYTHON常用库 一些PYTHON常用库
python代码python的一些编写代码,初学者python的一些编写代码,初学者
随机森林、机器学习、特征提取算法、ch4-featureSelection-randomForest《python machine learning》Raschka
faif python-patterns 使用Python实现一些设计模式的例子
Python_Kaldi_Feature Python 编写的 Kaldi 功能 提取器功能 请参阅featurebin/ 。 您应该更改conf/并编写一个.ini文件作为配置文件。 请注意,您可以将多个设置写入一个.ini并且可以使用config_section 您应该...
python初步尝试的一些结果,有一些基本函数的使用
资源分类:Python库 所属语言:Python 资源全名:featuretools-0.1.14.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Gabor函数是一个用于边缘提取的线性滤波器。Gabor滤波器的频率和方向表达同人类视觉系统类似。研究发现,Gabor滤波器十分适合纹理表达和分离。在空间域中,一个二维Gabor滤波器是一个由正弦平面波调制的高斯核函数。