gpt4 book ai didi

python - 字符串到字典 Python

转载 作者:太空狗 更新时间:2023-10-30 02:12:53 26 4
gpt4 key购买 nike

例如我有这样一行:

iamonlywhoknock BREAKINGBAD

什么意思

'iamonlywhoknock BREAKINGBAD\n'

它是 str,但我需要像这样创建 Dict:

{"iamonlywhoknock":"BREAKINGBAD"}

有什么想法吗?

最佳答案

是这样的吗?

>>> s='iamonlywhoknock BREAKINGBAD\n'
>>> k, v = s.split()
>>> {k: v}
{'iamonlywhoknock': 'BREAKINGBAD'}

关于python - 字符串到字典 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12990416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com