Unique entries in a vector

| categories: python | tags:

Matlab post

It is surprising how often you need to know only the unique entries in a vector of entries. In python, we create a “set” from a list, which only contains unique entries. Then we convert the set back to a list.

a = [1, 1, 2, 3, 4, 5, 3, 5]

b = list(set(a))
print b
[1, 2, 3, 4, 5]
a = ['a',
    'b',
    'abracadabra',
    'b',
    'c',
    'd',
    'b']

print list(set(a))
['a', 'c', 'b', 'abracadabra', 'd']

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter