notdone = [tuple((x,y))for x in range(5) for y in range(6)] 
for i in showns:
    s = lambda :tuple(random.sample(notdone,1)) #random.sample gives a LIST even though I used tuple()
    print notdone #debug
    a = s()
    print a #debug
    notdone.remove(a)
    b = s()
    flashcards[a] = Flashcard((x*20,y*100),i)
    flashcards[b] = Flashcard((x*20,y*100),i)


[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 0), (1, 1), (1, 2), (1, 3),
 (1, 4), (1, 5), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (3, 0), (3, 1),
 (3, 2), (3, 3), (3, 4), (3, 5), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5)]

((4, 0),)
Traceback (most recent call last):
  File "C:\Users\William\Desktop\memory.py", line 51, in <module>
    notdone.remove(a)
ValueError: list.remove(x): x not in list

I think it's because tuples are immutable, so their diffrent objects with the same value.
You see, (4,0) is in notdone.Why tuples?Because you can't hash a list. I'm using x,y coordinates so I can track it.

Recommended Answers

All 5 Replies

random.sample() returns a list. Try this

notdone = [tuple((x,y))for x in range(5) for y in range(6)]
from functools import partial
s = partial(random.choice, notdone)
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 0), (1, 1), (1, 2), (1, 3),
 (1, 4), (1, 5), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (3, 0), (3, 1),
 (3, 2), (3, 3), (3, 4), (3, 5), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5)]

((4, 1),)
Traceback (most recent call last):
  File "C:\Users\William\Desktop\memory.py", line 53, in <module>
    notdone.remove(a)
ValueError: list.remove(x): x not in list

Also, I knew it was a list.

I don't understand, it works very well:

>>> import random
>>> notdone = [tuple((x,y))for x in range(5) for y in range(6)]
>>> from functools import partial
>>> s = partial(random.choice, notdone)
>>> a = s()
>>> print(a)
(0, 5)
>>> notdone.remove(a)
>>> 

Notice that my code prints (0, 5) and not ((0, 5),).

uh, now the flashcards are tuples!

for i in showns:
    s = partial(random.choice, notdone)
    print notdone
    a = s()
    print a
    notdone.remove(a)
    b = s()
    flashcards[a] = Flashcard((x*20,y*100),i)
    flashcards[b] = Flashcard((x*20,y*100),i)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.