Iterating over a dictionary in python and stripping white space

后端 未结 7 547
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 01:10

I am working with the web scraping framework Scrapy and I am a bit of a noob when it comes to python. So I am wondering how do I iterate over all of the scraped items which

7条回答
  •  爱一瞬间的悲伤
    2021-01-13 01:36

    In a dictionary comprehension (available in Python >=2.7):

    clean_d = { k:v.strip() for k, v in d.iteritems()}
    

    Python 3.X:

    clean_d = { k:v.strip() for k, v in d.items()}
    

提交回复
热议问题