这段代码如何Pythonic
本文介绍了这段代码如何Pythonic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
str = 'title={WiMAX Power Amplifier Design based on Si-LDMOS},author={Nader, Charles and De Carvalho, Nuno Borges},journal={University of Galve, Sweden},year={2006}'
for item in str.split('},'):
try:
if 'author' in item:
print(item.split('{', 1)[1])
except Exception as e:
print(e)
解决方案
d = dict([s.split('={') for s in str.split('},')])
print(d['author'])
这篇关于这段代码如何Pythonic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文