ruby
[1] pry(main)> a = [[1, 2],[1,2],[3,4]]
=> [[1, 2], [1, 2], [3, 4]]
[2] pry(main)> a.uniq
=> [[1, 2], [3, 4]]
python
>>> a = [[1,2],[1,2],[3,4]]
>>> set(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
Certainly, tuple
works.
>>> b = [(1,2),(1,2),(3,4)]
>>> set(b)
set([(1, 2), (3, 4)])
but I want to add/delete items. A tuple does not support it. I had to convert the inner list to tuple. :(
>>> a = [[1,2],[1,2],[3,4]]
>>> b = []
>>> for i in a:
... b.append(tuple(i))
...
>>> set(b)
set([(1, 2), (3, 4)])
here
ruby
array.flatten
python
dead.