楼主: Enthuse
1165 4

Python: Comprehensions [推广有奖]

  • 4关注
  • 39粉丝

已卖:994份资源

大师

8%

还不是VIP/贵宾

-

威望
0
论坛币
75361 个
通用积分
825.9239
学术水平
103 点
热心指数
114 点
信用等级
86 点
经验
299244 点
帖子
12952
精华
0
在线时间
5848 小时
注册时间
2007-4-7
最后登录
2024-1-22

楼主
Enthuse 发表于 2015-5-8 23:03:44 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
all the following have the same behavior
1.
>>> res = []
>>> for x in 'spam':
res.append(ord(x)) # Manual results collection

2.
>>> res = list(map(ord, 'spam')) # Apply function to sequence (or other)

3
>>> res = [ord(x) for x in 'spam'] # Apply expression to sequence (or other)


Formal comprehension syntax:

[expresion for target in iterable]

more generally:

[ expression for target1 in iterable1 if condition1
for target2 in iterable2 if condition2 ...
for targetN in iterableN if conditionN ]
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:python comp COM MPR ONS expression following function sequence

沙发
Enthuse 发表于 2015-5-8 23:06:05

res = [x + y for x in [0, 1, 2] for y in [100, 200, 300]]

is same as

>>> res = []
>>> for x in [0, 1, 2]:
            for y in [100, 200, 300]:
                  res.append(x + y)

藤椅
auirzxp 学生认证  发表于 2015-5-8 23:29:44
提示: 作者被禁止或删除 内容自动屏蔽

板凳
h52101019 发表于 2015-5-18 14:31:08
thanks!

报纸
highspeed 发表于 2015-6-2 09:51:02
http://tech.pro/tutorial/1554/four-tricks-for-comprehensions-in-python

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-6 07:16