84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
如何定义一个Python函数,对给到的一个set或list,如:
set(1, 2, 3, 5, 6, 7, 8)
进行操作,判断连续的数字范围并分块,再返回如下字符串:
"1-3, 5-8"
刚学习Python, 对这些算法的实现还是有点迷茫,老司机们有没有好办法?谢谢!
学习是最好的投资!
Group by value minus subscript
# coding: utf-8 from itertools import groupby lst = [1, 2, 3, 5, 6, 7, 8, 11, 12, 13] fun = lambda (i, v): v - i for k, g in groupby(enumerate(lst), fun): print [v for i, v in g] #由于python3中lambda不支持用括号的方式解压,只能这样写 fun = lambda x: x[1] - x[0]
Group by value minus subscript