1

有没有更有效的方法来写这个只占用一行?这可行,但我觉得可以以某种方式将其压缩为一行代码

Python

del(thearticle['data-book-api'])
del(thearticle['data-book-human'])
del(thearticle['data-book'])
del(thearticle['data-chapter'])
del(thearticle['data-selected-verses'])
del(thearticle['data-verse-modal-enabled'])
del(thearticle['data-version'])
4

1 回答 1

2

用于:

for key in ['data-book-api', 'data-book-human', ...]:
    del thearticle[key]

顺便提一句。del不是函数。

于 2012-05-11T16:19:29.140 回答