如何将值从嵌套字典移动到另一个键?
我怎样才能编写一个通过这个测试的函数? 如果匹配,该函数需要从reading_list中删除DATA,并添加到空读取列表中
my_data = {'read': [], 'reading_list': [{'c': 'H', 'd': 3.5, 'data': 'this book'}]}
DATA = 'this book'
#this is test case...
def test_moves_book_from_reading_list_to_empty_read():
# Arrange
my_data = {
"reading_list": [{
"title": DATA,
"writer": WRITER,
"rating": RATING_1
}],
"read": []
}
# Act
updated_data = read_book(my_data, DATA)
# Assert
assert len(updated_data["reading_list"]) is 0
assert len(updated_data["read"]) is 1
How I can write a function that pass this test?
this function need to remove DATA from reading_list if match, and add to empty read list
my_data = {'read': [], 'reading_list': [{'c': 'H', 'd': 3.5, 'data': 'this book'}]}
DATA = 'this book'
#this is test case...
def test_moves_book_from_reading_list_to_empty_read():
# Arrange
my_data = {
"reading_list": [{
"title": DATA,
"writer": WRITER,
"rating": RATING_1
}],
"read": []
}
# Act
updated_data = read_book(my_data, DATA)
# Assert
assert len(updated_data["reading_list"]) is 0
assert len(updated_data["read"]) is 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这有用。
Hope this is useful.