Having trouble getting pyhon to repeat things for me.
What I wanted to test was python's random.sample.
So say I have a list
myList = range(1, 15)
I can for a single time do this
import random
>>> myList = range(1,15)
>>> random.sample(myList, 3)
[10, 6, 11]
>>>
I would like to be able to output
[10, 6, 11]
[1, 9, 3]
[8, 7, 2]
[1, 8, 11]
etc up to a statistic large range. Then count the occurrence of each item at its position in the list.
But I am looking at counter example from Python Collections
>>> cnt = Counter()
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
... cnt[word] += 1
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})
But what I want to do is create sets out of random.sample(myList, 3) say 100 times and then check the count of the occurrences of items frequency.
So this is what I thought would work but list isn't a valid type.
>>> cnt = collections.Counter()
>>> for sample in range(100):
... a = random.sample(myList, 3)
... cnt[a] += 1
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
TypeError: unhashable type: 'list'
So I changed it up a little but still failed.
>>> cnt = collections.Counter()
>>> for sample in range(100):
... a = random.sample(myList, 3)
... cnt[0] [1] [2] += 1
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
TypeError: 'int' object has no attribute '__getitem__'
>>>