-2

Is there any way to remove duplicates in a list through Regular expression If we have duplicates in it. without using set operation

["name1", "name2", "name3", "name4", "name1", "name2", "name3", "name4"]

I want output as

["name1", "name2", "name3", "name4"]
himabindu
  • 336
  • 3
  • 15

1 Answers1

0

As many of the comments have said, set() is probably what you want in python.

set(["name1", "name2", "name3", "name4", "name1", "name2", "name3", "name4"])

>> ["name1", "name2", "name3", "name4"]

If you really need to use a regex, use the re package along with a regex solution, such as How do I find and remove duplicate lines from a file using Regular Expressions?

tgpz
  • 161
  • 10