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 ...
随机推荐
- 开源库BaseRecyclerViewAdapterHelper
相信大家RecyclerView应该不会陌生,大多数开发者应该都使用上它了,它也是google推荐替换ListView的控件,但是用过它的同学应该都知道它在某些方面并没有ListView使用起来方便, ...
- 【Android 应用开发】分析各种Android设备屏幕分辨率与适配 - 使用大量真实安卓设备采集真实数据统计
.主要是为了总结一下 对这些概念有个直观的认识; . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/198 ...
- UE4 创建自己的角色
首先,需要在UE4中设置自己需要输入的按键,点击工具栏的Settings/ProjectSettings,找到input,在Bindings下添加自己需要的输入按键,我这里绑定了JumpBtn.Mov ...
- kettle简介(整体架构,运行方式,使用方法)
项目负责人Matt的说法:把各种数据放到一个壶里,然后呢,以一种你希望的格式流出.呵呵,外国人都很有联想力.看了提供的文档,然后对发布程序的简单试用后,可以很清楚得看到Kettle的四大块: Chef ...
- Logistic Regression求解classification问题
classification问题和regression问题类似,区别在于y值是一个离散值,例如binary classification,y值只取0或1. 方法来自Andrew Ng的Machine ...
- ORACLE EBS AP invoice 到付款的数据流
--1.Invoice创建时生成数据如下表 --Invoice主表 SELECT * FROM AP_INVOICES_ALL A WHERE A.INVOICE_NUM = '20111213001 ...
- 是我out了,c11标准出炉鸟
gcc -std=c11 -Wall -O3 -g0 -s -o x.c x 或者 clang -std=c11 -Wall -O3 -g0 -s -o x.c x 来吧! 我是有多无聊啊 测试代码: ...
- Linux系统下常用的快捷键
快捷键 ctrl + shift + '+' 将当前的终端放大 ctrl + '-' 将当前的终端放小 ctrl + l 清屏 ctrl + u ...
- OVS+DPDK Datapath 包分类技术
本文主体内容译于[DPDK社区文档],但并没有逐字翻译,在原文的基础上进行了一些调整,增加了对TSS分类器的详细阐述. 1. 概览 本文描述了OVS+DPDK中的包分类器(datapath class ...
- Unity脚本编程之——协程(Coroutine)
本文翻译自Unity官方文档:https://docs.unity3d.com/Manual/Coroutines.html 专有名词: Coroutine 协程 Alpha 不透明度 当你调用一个函 ...