1- "原地"排序-转换后替换

>>> list = [2,1,3]
>>> list.sort()
>>> list
[1, 2, 3]

降序 reverse = True

>>> list.sort(reverse = True)
>>> list
[3, 2, 1, 1]

2- "复制"排序-转换然后返回

>>> data = []

>>> list = [3,2,4,1]

>>> data = sorted(list)

>>> data

[1, 2, 3, 4]

>>> list

[3, 2, 4, 1]

>>>

降序参数 reverse = True

>>> data = sorted(list, reverse = True)
>>> data
[5, 3, 2, 1] 

3- "方法串链"-从左向右读,对数据应用一组方法

     try:
with open(filename) as f:
data = f.readline()
return ( data.strip().split(','))

4- "函数串链"-从右向左读,对数据应用一组函数

print( sorted( set ([sanitize(s) for s in julie]) )[0:3] ) 

5- "列表推导" - 在一行上指定一个转换(不是使用迭代)

>>> new_l = []
>>> for each_item in old_l:
... new_l.append(len(each_item))

可用下面方法替换

>>> new_l = []
>>> new_l = [ len(s) for s in old_l ]

6- "分片" 从一个列表访问多个列表项 [1:2] 不包含2,只显示第1个项目, 从0开始

>>> list = [1,2,3,4]
>>> list[1:2]
[2]
>>> list[1:3]
[2, 3]
>>>

7- "集合"- 一组无序的数据项,其中不包含重复项,使用set工厂

>>> list = [1,1,2,3]
>>> set( list )
{1, 2, 3}
print( sorted( set ([sanitize(s) for s in james]) )[0:3] )

[Head First Python]5. summary的更多相关文章

  1. [Head First Python]6. summary

    1- 字典-内置数据结构,数据值与键值关联 键-字典中查找部分 值-字典中数据部分 使用dict()工厂函数或者只用{}可以创建一个空字典 >>> list = {} >> ...

  2. [Head First Python]4. summary

    1- strip()方法可以从字符串去除不想要的空白符 (role, line_spoken) = each_line.split(":", 1) line_spoken = li ...

  3. Python Syntax Summary

    # _*_ coding: utf-8 _*_ """########################################################## ...

  4. Python初体验

    今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...

  5. C#调用Python脚本打印pdf文件

     介绍:通过pdf地址先将文件下载到本地,然后调用打印机打印,最后将下载的文件删除. 环境:windows系统.(windows64位) windows系统中安装python3.6.2环境 资料: O ...

  6. 05基于python玩转人工智能最火框架之TensorFlow基础知识

    从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...

  7. Python实例--C#执行Python脚本,传参

    # -*- coding: utf-8 -*- # 第一行的目的,是为了让代码里面,可以有中文注释信息. (否则要运行报错) # 这个 Python 脚本, 用于被 C# 来调用. # 简单测试 He ...

  8. Cheatsheet: 2013 09.22 ~ 09.30

    Other Python basics summary Another article about big O notation Mobile Getting Started with PhoneGa ...

  9. TensorFlow应用实战 | TensorFlow基础知识

    挺长的~超出估计值了~预计阅读时间20分钟. 从helloworld开始 mkdir 1.helloworld cd 1.helloworldvim helloworld.py 代码: # -*- c ...

随机推荐

  1. Lua 字符串 匹配模式 总结

    字符类 %a --字母alpha %d --数字double %l --小写字母lower %u --大写字母upper %w --字母和数字word %x -- 十六进制 %z --代表0 zero ...

  2. python代码风格规范

    类注释模板: :: class AnotherClass: """ 类注释 """ def method(self, arg1, arg2, ...

  3. Effective Java2读书笔记-对于所有对象都通用的方法(三)

    第12条:考虑实现Comparable接口 这一条非常简单.就是说,如果类实现了Comparable接口,覆盖comparaTo方法. 就可以使用Arrays.sort(a)对数组a进行排序. 它与e ...

  4. VirtualBox修改虚拟盘路径

    VirtualBox虚拟盘路径默认是存在C盘的,而当我们发现C盘不够用的时候,想转移就感觉有点麻烦了,现在给大家介绍一个简单又使用的方法. 第一步:到默认目录C:\Users\Administrato ...

  5. hdu 1255 覆盖的面积

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 #include <cstdio> #include <cstring> #inc ...

  6. PHP CI框架下,如果配置NGINX(根目录和子目录两种模式)

    摸索了一会儿,先配置成功,再看看PATH_INFO之类的东东吧. A,根目录: location ~ \.php($|/) { root html; fastcgi_pass ; fastcgi_in ...

  7. LeetCode_implement strstr ()

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

  8. VirtualBox 修改UUID实现虚拟硬盘复制

    最近用VirtualBox创建虚拟机,复制了一个虚拟硬盘之后,直接添加到列表,发现无法使用....提示为UUID已经被使用. 查找了一下解决方法:一般的介绍说操作方法为: 在命令行中,打开Virtua ...

  9. php安装pear、pecl

    安装pear.pecl特别简单,只需要两步. wget http://pear.php.net/go-pear.phar php go-pear.phar [root@localhost bin]# ...

  10. 【转】android 兼容性测试 CTS 测试过程(实践测试验证通过)

    原文网址:http://blog.csdn.net/jianguo_liao19840726/article/details/7222814 写这个博客的时候是为了记忆,建议大家还是看官方的说明,官方 ...