惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
博客园_首页
博客园 - 叶小钗
Blog — PlanetScale
Blog — PlanetScale
The Cloudflare Blog
量子位
人人都是产品经理
人人都是产品经理
小众软件
小众软件
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
Attack and Defense Labs
Attack and Defense Labs
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
Forbes - Security
Forbes - Security
罗磊的独立博客
Webroot Blog
Webroot Blog
美团技术团队
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
C
Check Point Blog
V2EX - 技术
V2EX - 技术
The Last Watchdog
The Last Watchdog
Microsoft Azure Blog
Microsoft Azure Blog
AI
AI
Cloudbric
Cloudbric
Application and Cybersecurity Blog
Application and Cybersecurity Blog
W
WeLiveSecurity
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
B
Blog RSS Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
LINUX DO - 热门话题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
O
OpenAI News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
C
Cyber Attacks, Cyber Crime and Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
Know Your Adversary
Know Your Adversary

博客园 - 行者无疆

mac上fisco bcos3.0安装部署 linux安装nginx python学习-时间序列 python学习-数据聚合与分组运算 数据分析指标 数据分析 搜索求解 人工智能概述 R语言学习 mac 安装anaconda和环境配置 python学习-数据规整 python学习-pandas python学习-数据清洗 python学习-NumPy基础 docker 常用命令 css学习 windows service install vs2003下的wap开发 一个div遮照的简单实现
python基础语法
行者无疆 · 2020-05-05 · via 博客园 - 行者无疆
values=1,2,3,4,5
a,b,*_ = values   #元组拆包
list((1,2,3))  #元组转列表

alist =[2,3,7,2]
2 in alist   #判断是否在列表里

alist + ['a','b','c',4]  #合并列表
#切片
seq=[7,2,3,7,5,6,0,1]
seq[-4:]      #[5, 6, 0, 1] 从结尾倒数第四个开始取数
seq[-6:-2]   #[6, 3, 5, 6]
seq[::2]       #[7, 3, 3, 6, 1] 间隔2个取一次数
seq[::-1]     #[1,0,6,5,3,6,3,2,7]  反转

some_list = ['foo', 'bar', 'baz']
mapping = {}
for i, v in enumerate(some_list):
    mapping[i]=v
#{0: 'foo', 1: 'bar', 2: 'baz'} 获取值

#zip 生成元组
seq1 = ['foo', 'bar', 'baz']
seq2 = ['one', 'two', 'three']
zipped = zip(seq1, seq2)
list(zipped)
#[('foo', 'one'), ('bar', 'two'), ('baz', 'three')]

for i, (a, b) in enumerate(zip(seq1, seq2)):
    mapping[i] =(a, b)
mapping
#{0: ('foo', 'one'), 1: ('bar', 'two'), 2: ('baz', 'three')}

tupt =[('foo', 'one'), ('bar', 'two'), ('baz', 'three')]
a,b =zip( *tupt )
a,b
#(('foo', 'bar', 'baz'), ('one', 'two', 'three'))


list(reversed(range(10)))  #反转
#[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
#序列转字典1
#mapping = {}
#for key, value in zip(key_list, value_list):
#mapping[key] = value

#序列转字典2
mapping = dict(zip(range(5), reversed(range(5))))
mapping
#{0: 4, 1: 3, 2: 2, 3: 1, 4: 0}

#获取设置字典默认值

value = some_dict.get(key, default_value)

words = ['apple', 'bat', 'bar', 'atom', 'book']
#方法一
by_letter = {}
for word in words:
    letter=word[0]
    if letter  in by_letter:
        by_letter[letter].append(word)
    else:
        by_letter[letter]= [word]
#方法二

for word in words:
    letter = word[0] 
    by_letter.setdefault(letter, []).append(word)
#检查是否可以hash
hash('string')
#如果希望数组作为key的话需要转我元组
d={}
d[tuple([1, 2, 3])] = 5
#创建集合set的2种方式
set([2, 2, 2, 1, 3, 3])
{2,2,2,1,3,3}
#输出{1,2,3}
#[expr for val in collection if condition]
strings = ['a', 'as', 'bat', 'car', 'dove', 'python']
[x.upper() for x in strings if len(x) > 2]
#['BAT', 'CAR', 'DOVE', 'PYTHON']
#字典
#dict_comp = {key-expr : value-expr for value in collection if condition}
#集合
#set_comp = {expr for value in collection if condition}
{len(x) for x in strings}
set(map(len, strings))
# 输出:{1, 2, 3, 4, 6}
 {val : index for index, val in enumerate(strings)}
#{'a': 0, 'as': 1, 'bat': 2, 'car': 3, 'dove': 4, 'python': 5}

 all_data = [['John', 'Emily', 'Michael', 'Mary', 'Steven'],['Maria', 'Juan', 'Javier', 'Natalia', 'Pilar']]
  names_of_interest = [] 
for names in all_data:
    enough_es = [name for name in names if name.count('e') >= 2] 
    names_of_interest.extend(enough_es)
[name for names in all_data for name in names if name.count('e') >= 2]
#['Steven']
#yield使用
def squares(n=10):
    print('Generating squares from 1 to {0}'.format(n ** 2))
    for i in range(1, n + 1):
        yield i**2
gen = squares()
for x in gen:
    print(x,end=' ')
#Generating squares from 1 to 100
#1 4 9 16 25 36 49 64 81 100