Simon Rechermann
Simon Rechermann

Reputation: 501

what's the point behind converting a List to an Set and than back to a List in python?

i just found this code in a project i'm working on:

applicant_function = []
for ...:
    applicant_function.append(...)
...
applicant_function = list(set(applicant_function))

does anyone have an idea what's the meaning behind this?

Upvotes: 1

Views: 34

Answers (2)

Dhaval Taunk
Dhaval Taunk

Reputation: 1672

The meaning is this:-

applicant_function = []   #initializing an empty list
for ...:         #for loop initialization
    applicant_function.append(...)     #appending elements to list
...
applicant_function = list(set(applicant_function))    #converting applicant_function to a set to remove duplicate elements.

Upvotes: 0

Balint G.
Balint G.

Reputation: 622

A set does not allow duplicates. The purpose is presumably to obtain a list without duplicates (every element appears at most once in the list).

Upvotes: 1

Related Questions