- 论坛徽章:
- 4
|
楼上的够简洁。
给个自己写的。- >>> s = '''zhang San,11/1/2012 8:00,
- zhang San,11/1/2012 17:00,
- li si, 11/1/2012 8:05,
- li si, 11/1/2012 17:03,
- wang wu, 11/1/2012 9:00,
- zhang San,11/2/2012 17:05,
- li si, 11/2/2012 8:01,
- li si, 11/2/2012 16:59,
- wang wu, 11/2/2012 8:00,
- wang wu, 11/2/2012 8:05,
- wang wu, 11/2/2012 17:04,'''
- >>> s = s.split('\n')
- >>> s = [i.split(',')[:-1] for i in s]
- >>> s = [[i.strip()+',' for i in j] for j in s]
- >>> d={}
- >>> for i in s:
- if i[0] in d:
- d[i[0]].append(i[1])
- else:
- d[i[0]] = i[-1:]
-
- >>> for i in d:
- print(i+''.join(d[i]))
-
- li si,11/1/2012 8:05,11/1/2012 17:03,11/2/2012 8:01,11/2/2012 16:59,
- wang wu,11/1/2012 9:00,11/2/2012 8:00,11/2/2012 8:05,11/2/2012 17:04,
- zhang San,11/1/2012 8:00,11/1/2012 17:00,11/2/2012 17:05,
复制代码 |
|