【发布时间】:2019-09-16 04:30:57
【问题描述】:
我正在尝试从列表中获取值后删除它。该列表位于字典内的列表中。
到目前为止,我一直在修改以下内容:
for data in this.customer_data:
for loans in data['loaned_books']:
if val_to_pop in loans:
print(loans[2])
loans.pop(2)
print(loans)
这给了
UML for dummies
[24, 'Feiten', True]
这非常接近我想要的,但是当我尝试删除该值所在的列表时,它变得非常模糊。我似乎不能remove(),也不想给它一个固定的索引号,因为它是一个动态列表
相关代码:
class Customer(Person):
def __init__(this, number, gender, given_name, surname, street_address, zip_code, city, email, username, telephone):
super().__init__(gender, given_name, surname, street_address, zip_code, city, telephone)
this.number = number
this.email = email
this.username = username
this.customer_data = [{'number': this.number, 'gender': this.gender, 'given_name': this.given_name, 'surname': this.surname, 'street_address': this.street_address,
'zip_code': this.zip_code, 'city': this.city, 'email': this.email, 'username': this.username, 'telephone': this.telephone, 'loaned_books': []}]
key 'loaned_book' 包含的堆栈:
[[24, 'Feiten', 'UML for dummies', True], [24, 'Feiten', 'Word Art', True]]
任何帮助将不胜感激!谢谢!
【问题讨论】:
标签: python-3.x oop dictionary nested-lists