>>> seq=['foo','x41','?','***']
>>> def func(x):
return x.isalnum()

>>> list(filter(func,seq))
['foo', 'x41']
>>> seq
['foo', 'x41', '?', '***']
>>> [x for x in seq if x.isalnum(),seq]
SyntaxError: invalid syntax
>>> [x for x in seq if x.isalnum()]
['foo', 'x41']
>>> list(filter(lambda x: x.isalnum(),seq))
['foo', 'x41']
>>> list(filter(None,[1,2,0,4,0,6]))
[1, 2, 4, 6]
>>> [1,2,3,4,5]-[2,3]
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
[1,2,3,4,5]-[2,3]
TypeError: unsupported operand type(s) for -: 'list' and 'list'
>>> import random
>>> x=[random.randint(1,100)for i in range(10)]
>>> x
[82, 2, 90, 58, 81, 18, 42, 40, 19, 94]
>>> list(map(lambda i: i+5,x))
[87, 7, 95, 63, 86, 23, 47, 45, 24, 99]
>>> y=[random.randint(1,10)for i in range(10)]
>>> y
[4, 8, 10, 10, 7, 2, 9, 1, 7, 4]
>>> import operator
>>> sum(map(operator.mul,x,y))
3354
>>> sum((i*j for i,j in zip(x,y)))
3354
>>> list(map(operator.add,x,y))
[86, 10, 100, 68, 88, 20, 51, 41, 26, 98]
>>> list(map(lambda i,j: i+j, x, y))
[86, 10, 100, 68, 88, 20, 51, 41, 26, 98]
>>> aList=[x*x for x in range(10)]
>>>
>>> aList
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> aList=[]
>>> for x in range(10)
SyntaxError: invalid syntax
>>> for x in range(10):
aList.append(x*x)

>>> aList
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> aList=list(lambda x: x*x, range(10))
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
aList=list(lambda x: x*x, range(10))
TypeError: list() takes at most 1 argument (2 given)
>>> aListt=list(map(lambda x:x*x, range(10)))
>>> aListt
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> freshfruit=['banana','loganberry','passion fruit']
>>> aList=[w.strip() for w in freshfruit]
>>> aList
['banana', 'loganberry', 'passion fruit']
>>> freshfruit=['banana','loganberry','passion fruit']
>>> aList=[]
>>> for item in freshfruit:
aList.append(item.strip())

>>> aList
['banana', 'loganberry', 'passion fruit']
>>> freshfruit=['banana','loganberry','passion fruit']
>>> aList =list(map(lambda x: x.strip(),freshfruit))
>>> aList
['banana', 'loganberry', 'passion fruit']
>>> freshfruit=['banana','loganberry','passion fruit']
>>> aList=list(map(str.strip,freshfruit))
>>> aList
['banana', 'loganberry', 'passion fruit']
>>> sum([2**x for x in range(64)])
18446744073709551615

python_code list_3的更多相关文章

  1. python_code list_2

    >>> import math>>> math.sin(0.5)0.479425538604203>>> >>> import ...

  2. python_code list_1

    >>> def is_not_empty(s): return s and len(s.strip()) > 0 >>> filter(is_not_empt ...

  3. python 数据类型 --- 集合

    1. 注意列表和集合的区别 set 列表表现形式: list_1 = [1,3,4];  集合表现形式:set_1= set() list_1 = [1,2,3,4,23,4,2] print(lis ...

  4. MyBatis传入多个参数的问题

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

  5. mybatis传入多个参数

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

  6. Python-03-基础

    一.集合 集合(set)是一个无序的.不重复的元素组合,它的主要作用如下: 去重:把一个列表变成集合,就会自动去重. 关系测试:测试两组数据之前的交集.差集.并集等关系. 常用操作 # 创建数值集合 ...

  7. Python学习Day2笔记(集合和文件操作)

    1.集合的使用 列表是有序的可包含重复内容的 集合是无序的不可包含重复内容的 1) 集合关系测试 #列表去重list_1=[1,4,5,6,7,8,9,7,5,4,23,2] #有重复数据 list_ ...

  8. Python Day3

    一.set集合 集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 # 创建数值集合 list_1 = ...

  9. ListView列表的简单案例

    在android开发中ListView它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示.抽空把对ListView的使用做了整理,并写了个小例子 列表示例图: BaseActivity pa ...

随机推荐

  1. 跨平台移动APP开发进阶(二)HTML5+、mui开发移动app教程

    前端开发APP,从HBuilder开始~ 序 通过 HTML5 开发移动App 时,会发现HTML5 很多能力不具备.为弥补HTML5 能力的不足,在W3C 中国的指导下成立了www.HTML5Plu ...

  2. 【一天一道LeetCode】#50. Pow(x, n)

    一天一道LeetCode系列 (一)题目 Implement pow(x, n). (二)解题 题目很简单,实现x的n次方. /* 需要注意一下几点: 1.n==0时,返回值为1 2.x==1时,返回 ...

  3. Leetcode_111_Minimum Depth of Binary Tree

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41964249 Minimum Depth of Binar ...

  4. hadoop 部署和调优

    一.集群安装 1.在所有的机器上建立相同的用户名,如:hadoop. $adduser hadoop $passwd hadoop 2.在/etc/hosts中添加机器名和IP hadoop@hado ...

  5. LIRe提供的图像检索算法的速度

    本文翻译了LIRe的作者Mathias Lux发表的论文<LIRe: Lucene Image Retrieval - An Extensible Java CBIR Library>.主 ...

  6. 芯片SIAT-002测试PCB板设计

    这个板子,从原理图到PCB板,总共画了6天,接近一个星期!虽然说各种麻烦,但总算学到了一些新知识.谨记以备后查. 附注: 模拟地与数字地详解 单片机晶振电路 1. 走线规划 针对采用BGA封装及引脚数 ...

  7. PS 图像调整算法——阈值

    PS里面这个算法,先将图像转成灰度图像,然后根据给定的阈值,大于该阈值的像素赋值为1,小于该阈值的赋值为0. if x>T, x=1; if x<T, x=0; 原图: 效果图:阈值为 1 ...

  8. LeetCode(38)-Valid Sudoku

    题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  9. linux上搭建ftp服务器

    摘要 vsftpd 是"very secure FTP daemon"的缩写,安全性是它的一个最大的特点.vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行 ...

  10. spring中一些aware接口

    Spring中提供一些Aware相关接口,像是BeanFactoryAware. ApplicationContextAware.ResourceLoaderAware.ServletContextA ...