请帮助
value = 'http://localhost:8001/issues/load?project_name=react&since=2016-03-24&until=2017-03-25&state=closed&sort=created&direction=asc&per_page=100&labels=Type:%20Bug'
hashing = hash(value)
words = value.split('&')
for data in words:
words2 = data.split('=')
print(words2)
答案 0 :(得分:0)
由于words2
每个都分为两个:
['http://localhost:8001/issues/load?project_name', 'react']
['since', '2016-03-24']
['until', '2017-03-25']
使用它将值添加到字典中:
>>> key_vals = {}
>>> for data in words:
... words2 = data.split('=')
... key_vals[words2[0]] = words2[1]
...
>>> pprint.pprint(key_vals)
{'direction': 'asc',
'http://localhost:8001/issues/load?project_name': 'react',
'labels': 'Type:%20Bug',
'per_page': '100',
'since': '2016-03-24',
'sort': 'created',
'state': 'closed',
'until': '2017-03-25'}
key_vals
的作业可以简化为:
key_vals = {key: val for (key, val) in [data.split('=') for data in words]}