python_code list_3
>>> 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的更多相关文章
- python_code list_2
>>> import math>>> math.sin(0.5)0.479425538604203>>> >>> import ...
- python_code list_1
>>> def is_not_empty(s): return s and len(s.strip()) > 0 >>> filter(is_not_empt ...
- python 数据类型 --- 集合
1. 注意列表和集合的区别 set 列表表现形式: list_1 = [1,3,4]; 集合表现形式:set_1= set() list_1 = [1,2,3,4,23,4,2] print(lis ...
- MyBatis传入多个参数的问题
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- mybatis传入多个参数
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- Python-03-基础
一.集合 集合(set)是一个无序的.不重复的元素组合,它的主要作用如下: 去重:把一个列表变成集合,就会自动去重. 关系测试:测试两组数据之前的交集.差集.并集等关系. 常用操作 # 创建数值集合 ...
- Python学习Day2笔记(集合和文件操作)
1.集合的使用 列表是有序的可包含重复内容的 集合是无序的不可包含重复内容的 1) 集合关系测试 #列表去重list_1=[1,4,5,6,7,8,9,7,5,4,23,2] #有重复数据 list_ ...
- Python Day3
一.set集合 集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 # 创建数值集合 list_1 = ...
- ListView列表的简单案例
在android开发中ListView它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示.抽空把对ListView的使用做了整理,并写了个小例子 列表示例图: BaseActivity pa ...
随机推荐
- Android官方技术文档翻译——清单合并
本文译自Android官方技术文档<Manifest Merger>,原文地址:http://tools.android.com/tech-docs/new-build-system/us ...
- RHEL自动安装zookeeper的shell脚本
RHEL自动安装zookeeper的shell脚本 A:本脚本运行的机器,Linux RHEL6 B,C,D,...:待安装zookeeper cluster的机器, Linux RHEL6 首先在脚 ...
- Android特效专辑(八)——实现心型起泡飞舞的特效,让你的APP瞬间暖心
Android特效专辑(八)--实现心型起泡飞舞的特效,让你的APP瞬间暖心 马上也要放年假了,家里估计会没网,更完这篇的话,可能要到年后了,不过在此期间会把更新内容都保存在本地,这样有网就可以发表了 ...
- Linux性能监测:监测目的与工具
Linux性能监测:监测目的与工具介绍 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不是说现在优化了,测试了 ...
- Android实训案例(五)——四大组件之一ContentProvider的使用,通讯录的实现以及ListView的优化
Android实训案例(五)--四大组件之一ContentProvider的使用,通讯录的实现 Android四大组件是啥这里就不用多说了,看图吧,他们之间通过intent通讯 我们后续也会一一的为大 ...
- 【uWSGI】实战之Django配置经验
uWSGI 是应用服务器,实现了uwsgi, wsgi等协议,可以运行wsgi 应用 uwsgi 是协议名 Django配置 下面是自己经常用的一个配置模板,基于1.9以上的版本使用的, 主要基于dj ...
- python笔记--1
pip工具常用命令: pip命令示例 说明 pip download SomePackage[==version] 下载扩展库的指定版本,不安装 pip freeze [> requiremen ...
- 第1章-Struts2 概述 --- Struts2和MVC
(一)Struts2和MVC的关系图: (1)控制器---FilterDispatcher 用户请求首先达到前段控制器(FilterDispatcher).FilterDispatcher负责根据用户 ...
- MDF,了解一下
1.MDF定义 MDF,全称(Measurement Data Format),即测量数据格式,是ASAM(自动化及测量系统标准协会)定义的.MDF的网页https://www.asam.net/st ...
- tomcat启动非常慢;连接oracle数据库失败,jdbc错误日志提示connection reset;测试主机间网络互通及数据库端口都正常
[判断确认:这时候大家可能要去检查一下/dev/random 这个设备档案.可以用cat /dev/random 来看它的内容,如果你发现他一直没显示任何内容﹝可能是乱码数字之类的﹞,那就是它出问 ...