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. 搭建phonegap开发环境,搭建安卓开发环境

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  2. 生成bundle和移除bundle

    1.命令行生成bundle $ php bin/console generate:bundle --namespace=Acme/TestBundle 2.移除bundle(新的bundle) App ...

  3. Hdu1108(最小公倍数)

    #include <stdio.h> int main() { int Num1,Num2; while(scanf("%d %d",&Num1,&Nu ...

  4. C语言递归分析

    思路 下图描述的是从问题引出到问题变异的思维过程: 概述 本文以数制转换为引,对递归进行分析.主要是从多角度分析递归过程及讨论递归特点和用法. 引子 一次在完成某个程序时,突然想要实现任意进制数相互转 ...

  5. sql数据库监控语句

    --查找被阻塞进程 --查找阻塞头进程 and exists ( from master..sysprocesses where blocked =p.spid) --查找等待时间长的进程 order ...

  6. cf C. Tourist Problem

    http://codeforces.com/contest/340/problem/C #include <cstdio> #include <cstring> #includ ...

  7. 《Programming WPF》翻译 第5章 2.内嵌样式

    原文:<Programming WPF>翻译 第5章 2.内嵌样式 每一个“可样式化”的WPF元素都有一个Style属性,可以在内部设置这个属性--使用XAML属性-元素的语法(在第一章讨 ...

  8. Non-unique Elements

    Non-unique Elements You are given a non-empty list of integers (X). For this task, you should return ...

  9. hihoCoder 1041 国庆出游 (DFS)

    题意: 小Hi和小Ho准备国庆期间去A国旅游.A国的城际交通比较有特色:它共有n座城市(编号1-n):城市之间恰好有n-1条公路相连,形成一个树形公路网.小Hi计划从A国首都(1号城市)出发,自驾遍历 ...

  10. JAVA大整数傻瓜入门

    http://blog.csdn.net/skiffloveblue/article/details/7032290..先记着