立即学习:https://edu.csdn.net/course/play/26676/338786?utm_source=blogtoedu
列表解析
[i**2 for i in range(10)]
例题一:创建一个列表,其中元素是100以内且能被3整除的正整数
==>[i for i in range(100) if i%3==0]
例题二:字符串s='Life is short you need python'。统计字符串每个字母的数量
s=' Life is short You need python' d = {} for word in s: if word.isalpha(): if word in d: d[word] += 1 else: d[word] = 1 print(d)