Here’s an example of some data where the dates not formatted well for easy import into Excel:
The first column has the day and month separated by a space. The second column is year-day, which we’ll ignore. The third column has the time. The data we’re interested in is in the 9th column (temperature). The goal is to have a simple Excel file where the first column is date, and the second column is temperature.
|
2011年11月10日星期四
用Python的split输出excel文件
利用list(set())和sorted处理列表或字典
1.利用list(set(a))来删除列表a或者字典中重复的元素。
2.利用sorted 来排序字典a。排序原则:将列表b中元素按照其在字典a中对应值的大小来排序。Reference: http://wiki.python.org/moin/HowTo/Sorting/
>>> a={'a': '3', 'c': '2', 'e': '1', 'd': '0'}
>>> b=['a','e']
>>> sorted(b,key=a.__getitem__)
['e', 'a']
特殊地:
对字典a的 健值列表(a.keys()) 按其对应值的大小进行排序,结果输出到列表中
>>> a={'a':'3','c':'2','d':'0','e':'1'}
>>> sorted(a.keys(),key=a.__getitem__)
['d', 'e', 'c', 'a']
>>> a=['2','2','4','3','4','0','1','1']
>>> list(set(a))
['1', '0', '3', '2', '4']
2.利用sorted 来排序字典a。排序原则:将列表b中元素按照其在字典a中对应值的大小来排序。Reference: http://wiki.python.org/moin/HowTo/Sorting/
>>> a={'a': '3', 'c': '2', 'e': '1', 'd': '0'}
>>> b=['a','e']
>>> sorted(b,key=a.__getitem__)
['e', 'a']
特殊地:
对字典a的 健值列表(a.keys()) 按其对应值的大小进行排序,结果输出到列表中
>>> a={'a':'3','c':'2','d':'0','e':'1'}
>>> sorted(a.keys(),key=a.__getitem__)
['d', 'e', 'c', 'a']
订阅:
博文 (Atom)