kat

Python group by

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Assume that I have a such set of pair datas where index 0 is the value and the index 1 is the type: input = [ ('11013331', 'KAT'), ('9085267', 'NOT'), ('5238761', 'ETH'), ('5349618', 'ETH'), ('11788544', 'NOT'), ('962142', 'ETH'), ('7795297', 'ETH'), ('7341464', 'ETH'), ('9843236', 'KAT'), ('5594916', 'ETH'), ('1550003', 'ETH') ] I want to group them by their type(by the 1st indexed string) as such: result = [ { type:'KAT', items: ['11013331', '9843236'] }, { type:'NOT', items: ['9085267', '11788544'] }, { type:'ETH', items: ['5238761',

[CSP校内集训]kat

放肆的年华 提交于 2019-12-02 21:11:11
题意 一本有n道题的练习册,katarina大佬每天都会做k道题。 第一天做第1~k题,第二天做第2~k+1题……第n-k+1天做第n−k+1~n道题。 每道题有它的难度值,假设今天katarina大佬做的题目中最大难度为t,那么今天katarina大佬的劳累度就是 \(w_t\) ,做完这本书的劳累值就是每天的劳累值之和。 题目的难度在1~m随机,求做完整本书的期望劳累值 \(n,m \leq 500 , mod = 10^9+7\) 思路 由于前面两道题都有点迷所以还以为这道题也是道神题 性质 :求每种排列的贡献和 等价于 一个滑动窗口的贡献 \(\times\) \((n-k+1)\) ( 性感 )证明 根据题意有: \[ans = \sum_{i=1}^{m^n}{ (\frac{1}{m^n} \times (a_1^i + a_2^i + ....... + a_{n-k+1}^i)) }\] ,其中 \(a_j^i\) 表示在第 \(i\) 种排列下第 \(j\) 个滑动窗口的贡献 显然这个东西可以用乘法分配律按照 \(j\) 分开: \[ans = \sum_{j=1}^{n-k+1}{\frac{1}{m^n} \times (a_j^1 + a_j^2 + ....... + a_j^{m^n})}\] 对于一个滑动窗口

copy模块的copy和deepcopy函数

房东的猫 提交于 2019-11-30 05:53:19
>> > import copy >> > spam = [ 1 , 2 , 3 ] >> > cheese = copy . copy ( spam ) >> > cheese [ 1 ] = 42 >> > cheese [ 1 , 42 , 3 ] >> > spam [ 1 , 2 , 3 ] >> > kat = copy . deepcopy ( spam ) >> > kat [ 2 ] = 400 >> > kat [ 1 , 2 , 400 ] >> > spam [ 1 , 2 , 3 ] copy函数的存在即为了解决列表或者字典传递时,修改当前变量的值不影响原来列表或者字典的值。此时的spam和cheese指向了不同的列表 deepcopy同理 来源: https://blog.csdn.net/weixin_44478378/article/details/101118203