>>> 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. mysql进阶(二十三)数据库事务四大特性

    数据库事务四大特性       原子性.一致性.分离性.持久性 原子性  事务的原子性指的是,事务中包含的程序作为数据库的逻辑工作单位,它所做的对数据修改操作要么全部执行,要么完全不执行.这种特性称为 ...

  2. 《java入门第一季》之面向对象面试题(fianl关键字)

    /* 面试题:final修饰局部变量的问题 基本类型:基本类型的值不能发生改变. 引用类型:引用类型的(地址值)(不能发生改变),但是,该对象的堆内存的值是可以改变的. */ class Studen ...

  3. RabbitMQ 队列

    http://blog.chinaunix.net/uid/22312037/sid-163962-abstract-1.html http://bobo896.blog.163.com/blog/# ...

  4. JSP 知识基本

    from:http://blog.csdn.net/caipeichao2/article/details/38589293 more:http://www.2cto.com/kf/web/jsp/4 ...

  5. Java核心技术第四章——2.final 和 static

    final实例域 实例域(对象的属性)可修饰为final.修饰为final后,在构建对象时必须初始化这个实例域.若没有在实例域进行初始化,那么必须在每个构造器内初始化这个实例域(否则会编译错误). 表 ...

  6. Java IO学习--(一)概述

    在这一小节,我会试着给出Java IO(java.io)包下所有类的概述.更具体地说,我会根据类的用途对类进行分组.这个分组将会使你在未来的工作中,进行类的用途判定时,或者是为某个特定用途选择类时变得 ...

  7. iOS 字体权重weight

    UIFontWeightUltraLight  - 超细字体 UIFontWeightThin  - 纤细字体 UIFontWeightLight  - 亮字体 UIFontWeightRegular ...

  8. (function(){xxx})(); 写法解释

    常见格式:(function() { /* code */ })(); 解释:包围函数(function(){})的第一对括号向脚本返回未命名的函数,随后一对空括号立即执行返回的未命名函数,括号内为匿 ...

  9. CSS3实现多样的边框效果

    半透明边框 实现效果: 实现代码: <div> 你能看到半透明的边框吗? </div> div { /* 关键代码 */ border: 10px solid rgba(255 ...

  10. CDH安装系统环境准备——系统版本和安装包下载地址指南

    由于Hadoop深受客户欢迎,许多公司都推出了各自版本的Hadoop,也有一些公司则围绕Hadoop开发产品.在Hadoop生态系统中,规模最大.知名度最高的公司则是Cloudera.接下来的日子里, ...