Facebook Interview Question: Write a python program to rem... | Glassdoor.co.uk

Interview Question

Data Engineering Manager Interview London, England

Write a python program to remove duplicates , keep the

  first occurrance
Answer

Interview Answer

2 Answers

0

def remove_duplicates(input_list):
        unique_list = []
        count_num = set([])
       for num in input_list:
              if not count_num or i not in count_num:
                        unique_list.append(num)
                       count_num.add(num)
       return unique_list

Interview Candidate on 20 Jul 2018
0

Approach 1:
simply use set() function because set() can't have duplicates

list (set())

approach 2: Use inbuilt dictionary

list(dict.fromkeys ())

ANdy on 16 Dec 2018

Add Answers or Comments

To comment on this, Sign In or Sign Up.