2

Python 新手语法问题,为什么用 str split 后新建 dict 爆黄呢?

 1 year ago
source link: https://www.v2ex.com/t/895631
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

Python 新手语法问题,为什么用 str split 后新建 dict 爆黄呢?

  fenglala · code4lala · 1 小时 52 分钟前 · 385 次点击
str_x = 'int_value=233/str_value=hello'
dict_x = dict(element.split('=') for element in str_x.split('/'))
print(dict_x)
print(int(dict_x['int_value']))
print(dict_x['str_value'])

这段代码可以正常运行,但是为什么放到 pycharm 里爆黄呢,请问怎么改才能不爆黄呢?

dict()里边爆黄:

Unexpected type(s): (Generator[List[str], Any, None]) Possible type(s): (SupportsKeysAndGetItem[List[str], _VT]) (Iterable[Tuple[Any, Any]]) 

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK