Skip to content

Instantly share code, notes, and snippets.

@Cyril-Pop
Created September 6, 2020 14:48
Show Gist options
  • Save Cyril-Pop/1fa9b986de4b2b6df4dd6b1ea431c7d4 to your computer and use it in GitHub Desktop.
Save Cyril-Pop/1fa9b986de4b2b6df4dd6b1ea431c7d4 to your computer and use it in GitHub Desktop.
replace Item at Sublist at index
lst = [["A","B","C","D"], ["E","F","G","H"]]
replaceIndex = [[2, 3], [1, 2]]
replaceValue = [["C1", "D1"],["F1", "G1"]]
out = []
for sublst, lstidx, lstrep in zip(lst, replaceIndex, replaceValue):
for idx, rep in zip(lstidx, lstrep):
sublst[idx]=rep
out.append(sublst)
print (out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment