I
I
Igor Raskin2019-03-17 21:28:50
Python
Igor Raskin, 2019-03-17 21:28:50

Python two arrays. How to display unique values?

There are two arrays. Both consist of values ​​of type - String. It is necessary to write to any txt file unique array values ​​from the user.txt file that are not in the second array.
The first array is the lines in the .txt file
user.txt:
name1
name2
name3
name4
The second array is an array formed in the code from the names that must be excluded from the first array:
array_user_delete.append(users_r)
In general, I wanted to get the entire list in the txt file as output of the form
name1 +
name2 -
name3 +
name4 +
Where plus means that the name is present in array 2, and minus, on the contrary, that it is not. But I do not have enough knowledge either for this or simply to form at least a list of unique values. I do not show the whole code, because I'm afraid I'm so incompetent that they'll throw slippers at me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2019-03-17
@shinma

You can use sets:

a = [1, 2, 3]
b = [2, 3, 4]
print(set(a + b))
>>> {1, 2, 3, 4}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question