python - How to get output as a list after removing the duplicates in list? -


below python program remove duplicate ip addresses in list:

dup_ip = ['1.1.1.1','2.1.1.1','1.1.1.1','3.3.3.3','2.1.1.1','1.1.1.1','3.3.3.3',] empty_list=[] in dup_ip:     if not in empty_list:         empty_list.append(i)         print 

i getting output shown below:

c:\users\test\desktop>python dup_list.py 1.1.1.1 2.1.1.1 3.3.3.3  c:\users\test\desktop> 

but want output list shown below:

['1.1.1.1', '2.1.1.1','3.3.3.3'] 

how this?

you can print empty_list or better way is transform original dup_ip set , list if needed:

>>> dup_ip  = ['1.1.1.1', '2.1.1.1', '1.1.1.1','3.3.3.3', '2.1.1.1', '1.1.1.1', '3.3.3.3'] >>> unique_ip = list(set(dup_ip)) >>> print unique_ip ['2.1.1.1', '1.1.1.1', '3.3.3.3'] 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -