-1

I wish to trim the list

[0,0,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3, ... , 145,145,145]

into

[0,1,2,3,4,...,145]

I know the "C-Programming-style" way of doing it in Python.

I am here to ask for an intelligent and smart way of doing this.

Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174

3 Answers3

1

numpy.unique(mylist) or list(set(mylist)) should do.

PS And it is not 'trimming' - that's a different thing...

sashkello
  • 17,306
  • 24
  • 81
  • 109
1

Use set:

unique = [x for x in set(original)]

or

unique = list(set(original))
jason
  • 236,483
  • 35
  • 423
  • 525
0

Give this a try

print list(set(my_list))

scohe001
  • 15,110
  • 2
  • 31
  • 51