【376】COMP 9021 相关笔记(二)
- zip()
- itertools.zip_longest()
- %time
- for 循环单行输出
- list 技巧
- 迭代器
- 生成器
- map()
- zip()
from pathlib import Path
Path.glob:可以用来查询文件名
import csv
csv.reader:用来读取csv文件,每一行都是一个tuple
from collections import defaultdict
defaultdict(int):默认为0
defaultdict(list):默认为空表 []
# 通过字典来调用变量
aa = 'alex'
bb = 'brandon'
c = {'a':aa, 'b':bb}
c['a'][:2]
# 通过 print 方式写入数据
# 直接遍历 open 后的文件读取每行信息 import csv
for file in names_dir.glob('*.txt'):
with open(file) as name_file, \
open(npg_males / file.name, 'w') as males_file, \
open(npg_females / file.name, 'w') as females_file:
for line in name_file:
name, gender, count = line.split(',')
if gender == 'F':
print(name, count, sep = ',', end = '', file = females_file)
else:
print(name, count, sep = ',', end = '', file = males_file)
zip 高阶应用
说明:将 a 排序,然后按照 a 的排序规则,将 b 中的所有元素进行相应排序
a = ['B', 'A']
b = [[1, 0], [0, 1], [1, 2]] print(list(list(zip(*sorted(zip(a, *b))))[0]))
print(list(zip(*sorted(zip(a, *b))))[1:]) output:
['A', 'B']
[(0, 1), (1, 0), (2, 1)]
实现过程拆解如下:
a = ['B', 'A']
b = [[1, 0], [0, 1], [1, 2]] tmp = zip(a, *b) tmp_list = list(zip(*sorted(tmp))) print(list(tmp_list[0]))
print(tmp_list[1:])
【376】COMP 9021 相关笔记(二)的更多相关文章
- 【375】COMP 9021 相关笔记
1. Python 中的逻辑否定用 not 2. 对于下面的代码直邮输入整数才能运行,无论字符串或者浮点型都会报错 int(input('How many games should I simulat ...
- redis相关笔记(二.集群配置及使用)
redis笔记一 redis笔记二 redis笔记三 1.配置:在原redis-sentinel文件夹中添加{8337,8338,8339,8340}文件夹,且复制原8333中的配置 在上述8333配 ...
- jQuery源码笔记(二):定义了一些变量和函数 jQuery = function(){}
笔记(二)也分为三部分: 一. 介绍: 注释说明:v2.0.3版本.Sizzle选择器.MIT软件许可注释中的#的信息索引.查询地址(英文版)匿名函数自执行:window参数及undefined参数意 ...
- WPF的Binding学习笔记(二)
原文: http://www.cnblogs.com/pasoraku/archive/2012/10/25/2738428.htmlWPF的Binding学习笔记(二) 上次学了点点Binding的 ...
- python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码
python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码 淘宝IP地址库 http://ip.taobao.com/目前提供的服务包括:1. 根据用户提供的 ...
- docker学习笔记二:常用命令
docker学习笔记二:常用命令 查看docker常用命令 docker --help 返回结果如下: 其中常用的命令如下: 1.image相关操作 展示所有的image: 删除image: rmi ...
- HTTPS证书申请相关笔记
申请免费的HTTPS证书相关资料 参考资料: HTTPS 检测 苹果ATS检测 什么是ECC证书? 渠道2: Let's Encrypt 优点 缺点 Let's Encrypt 的是否支持非80,44 ...
- Linux学习笔记(二) 文件管理
了解 Linux 系统基本的文件管理命令可以帮助我们更好的使用 Linux 系统,以下介绍几个常用的文件管理命令 1.pwd pwd 是 Print Working Directory 的简写,用于显 ...
- amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules
amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules 一.总结 1.见名知意:见那些class名字知意,见函数名知意,见文件名知意 例如(HISTORY.md Web 组件更新历史 ...
随机推荐
- Zabbix故障总结(持续更新)
Zabbix housekeeper processes more than 75% busy 问题原因 为了防止数据库持续增大,zabbix有个自动删除历史数据的机制,就是housekeeper,而 ...
- vue学习笔记-初始化一个vue项目(1)
1.cnpm install -g vue-cliUsage:vue init <template-name> <project-name> 2.我们一般使用webpack模版 ...
- 轻型DNS服务器dnsmasq
源码安装 源码下载地址 apt 安装 apt install dnsmasq 编辑配置 vim /etc/dnsmasq.conf resolv-file=/etc/resolv.dnsmasq.co ...
- KVM总结-KVM性能优化之内存优化
我们说完CPU方面的优化(http://blog.csdn.net/dylloveyou/article/details/71169463),接着继续第二块内容,也就是内存方面的优化.内存方面有以下四 ...
- Android CoordinatorLayout实现多列表切换并和头布局联动;
注意:不是双列表联动,是多列表和头布局联动: 大概就是和饿了么店铺首页类似的布局框架吧,头布局显示时,列表RecyclerView或ScrollView和头布局一起滚动,头布局完全隐藏后列表再去滚动, ...
- RecyclerView中设置match_parent无效;
在RecyclerView中宽度设置了match_parent,但是效果和wrap_content一样: 说下解决方法: 1.这样子写,match_parent没有效果: View v = View. ...
- Java第一次上机实验源代码
小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...
- 点击DIV随机换颜色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- Ubuntu 16.04 fatal: Unable to find remote helper for 'https'
在Windows10 的Linux子系统下安装oh-my-zsh的时候出现如下错误: fatal: Unable to find remote helper for 'https' 网上有描述说没有安 ...
- linux web服务基础知识,dns
#web服务基础知识c/s 客户端/服务器b/s 浏览器/服务器 nginx > web server 服务端浏览器 > web client 客户端 #dns解析 ...