Issue
I have two lists, one with word and another one with word type like this
['fish', 'Robert', 'dog', 'ball', 'cat', 'dog', 'Robert']
['animal', 'person', 'animal', 'object', 'animal', 'animal', 'person']
I need to remove duplicates in the first list and to remove the type at the same index of the word removed.
In the end I need something like this:
['fish', 'Robert', 'dog', 'ball', 'cat']
['animal', 'person', 'animal', 'object', 'animal']
How can I do that?
Solution
just do a loop and use the zip function
Script
# Input Vars
a = ['fish', 'Robert', 'dog', 'ball', 'cat', 'dog', 'Robert']
b = ['animal', 'person', 'animal', 'object', 'animal', 'animal', 'person']
# Output Vars
c = []
d = []
# Process
for e, f in zip(a, b):
if(e not in c):
c.append(e)
d.append(f)
# Print Output
print(c)
print(d)
Output
['fish', 'Robert', 'dog', 'ball', 'cat']
['animal', 'person', 'animal', 'object', 'animal']
Answered By - Dean Van Greunen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.