编写一个函数或程序,它将采用2个整数“当前”和“目标”数组,并生成2个数组,表示添加列表和删除列表,以便将添加和删除应用于“当前“数组将产生”目标“数组。Python Array Diff
例如,给定以下 输入:
current = [1, 3, 5, 6, 8, 9]
target = [1, 2, 5, 7, 9]
的输出将是:
additions: [2, 7]
deletions: [3, 6, 8]
所以,以下为真:
电流([1, (3,5,7,9)] +添加物([2,7]) - 删除物([3,6,8])=目标物([1,2,5,7,9])
解决方案:
到目前为止,我有这样的:
---------------------------
# import array function
from array import array
# create an integer array named current
current = array('i', [1, 3, 5, 6, 8, 9])
# add items from additions list into current array using the fromlist() method
additions = [2, 7]
current.fromlist(additions)
# remove items on deletions list from current array using the. remove() method
current.remove(3)
current.remove(6)
current.remove(8)
什么问题? – Dekel
你能澄清“不起作用”吗?你有错误吗? – Dekel
道歉 - 它或多或少的作品,但是,当我一步一步地进入最终名单时, –