Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中H:M:S格式的按时间降序排序列表_Python_Python 3.x_Python 3.5 - Fatal编程技术网

Python中H:M:S格式的按时间降序排序列表

Python中H:M:S格式的按时间降序排序列表,python,python-3.x,python-3.5,Python,Python 3.x,Python 3.5,我正在尝试订购一个类似以下内容的列表: times = [] if (interval == '1min'): for item in data['Time Series (1min)']: times.append(item) ['2017-11-03 15:21:00'、'2017-11-03 15:03:00'、'2017-11-03 15:11:00', '2017-11-03 15:52:00', '2017-11-03 14:37:00', '2017-11-0

我正在尝试订购一个类似以下内容的列表:

times = []
if (interval == '1min'):
   for item in data['Time Series (1min)']:
       times.append(item)
['2017-11-03 15:21:00'、'2017-11-03 15:03:00'、'2017-11-03 15:11:00', '2017-11-03 15:52:00', '2017-11-03 14:37:00', '2017-11-03 14:32:00', '2017-11-03 15:20:00', '2017-11-03 14:30:00', '2017-11-03 14:43:00', '2017-11-03 14:58:00', '2017-11-03 15:58:00', '2017-11-03 15:42:00', '2017-11-03 14:59:00', '2017-11-03 15:40:00', '2017-11-03 14:35:00', '2017-11-03 14:21:00', '2017-11-03 15:26:00', '2017-11-03 15:50:00', '2017-11-03 15:13:00', '2017-11-03 15:53:00', '2017-11-03 14:40:00', '2017-11-03 15:16:00', '2017-11-03 14:45:00', '2017-11-03 15:33:00', '2017-11-03 15:35:00', '2017-11-03 15:36:00', '2017-11-03 14:23:00', '2017-11-03 15:10:00', '2017-11-03 15:37:00', '2017-11-03 14:54:00', '2017-11-03 15:44:00', '2017-11-03 15:23:00', '2017-11-03 14:47:00', '2017-11-03 15:43:00', '2017-11-03 14:48:00', '2017-11-03 14:41:00', '2017-11-03 15:45:00', '2017-11-03 15:09:00', '2017-11-03 15:06:00', '2017-11-03 15:08:00', '2017-11-03 14:57:00', '2017-11-03 15:17:00', '2017-11-03 14:52:00', '2017-11-03 15:14:00', '2017-11-03 15:19:00', '2017-11-03 15:25:00', '2017-11-03 15:48:00', '2017-11-03 15:24:00', '2017-11-03 15:57:00', '2017-11-03 15:28:00', '2017-11-03 15:34:00', '2017-11-03 15:59:00', '2017-11-03 14:53:00', '2017-11-03 14:50:00', '2017-11-03 14:55:00', '2017-11-03 15:56:00', '2017-11-03 15:46:00', '2017-11-03 15:32:00', '2017-11-03 16:00:00', '2017-11-03 15:29:00', '2017-11-03 14:34:00', '2017-11-03 15:04:00', '2017-11-03 14:38:00', '2017-11-03 15:07:00', '2017-11-03 14:39:00', '2017-11-03 14:25:00', '2017-11-03 14:51:00', '2017-11-03 14:33:00', '2017-11-03 14:46:00', '2017-11-03 14:22:00', '2017-11-03 15:47:00', '2017-11-03 14:42:00', '2017-11-03 15:27:00', '2017-11-03 15:41:00', '2017-11-03 15:55:00', '2017-11-03 15:31:00', '2017-11-03 14:56:00', '2017-11-03 14:49:00', '2017-11-03 15:39:00', '2017-11-03 15:01:00', '2017-11-03 14:29:00', '2017-11-03 14:27:00', '2017-11-03 14:44:00', '2017-11-03 15:49:00', '2017-11-03 15:30:00', '2017-11-03 15:51:00', '2017-11-03 15:54:00', '2017-11-03 15:22:00', '2017-11-03 14:31:00', '2017-11-03 14:28:00', '2017-11-03 14:26:00', '2017-11-03 15:15:00', '2017-11-03 14:24:00', '2017-11-03 15:00:00', '2017-11-03 15:38:00', '2017-11-03 14:36:00', '2017-11-03 15:18:00', '2017-11-03 15:05:00', '2017-11-03 15:12:00', “2017-11-03 15:02:00”

所以它看起来像:

['2017-11-03 16:00:00'、'2017-11-03 15:59:00'、'2017-11-03 15:58:00'等]

我想知道我如何才能做到这一点,但我也有兴趣知道如何通过将它们按顺序排列在一个列表中来先发制人地解决这个问题

我正在从一个json创建列表

我只是将每个项目添加到如下列表中:

times = []
if (interval == '1min'):
   for item in data['Time Series (1min)']:
       times.append(item)
但是我得到了之前的列表,它不符合顺序,即使你访问网页,时间是按降序排列的


感谢您的帮助

字符串没有正确排序,因为它们来自JSON字典。当JSON被转换成Python对象时,字符串会被放入Python dict中,而Python dict不会被排序

您只需要:


格式很方便,因为按字典顺序排列字符串将按时间顺序排列。

这就是我需要的!感谢您快速、简单、有效的回答!