Being rusty, I did
hands.extend( (b_hand + [card] for card in joker_cards('red')))
And, of course, I actually meant a list comprehension. I actually made myself look better here - I had first done list.append - which gave me a list of lists of lists, rather than a list of lists, which was what I wanted.. if it worked - which it didn't of course - giving me a generator expression. chatGPT told me to wrap the generator expression in list(), which I did - not thinking clearly..
All I needed was:
hands.extend( [b_hand + [card] for card in joker_cards('red')] )
Which leads us to the question of generator expressions - what? why? Where?..
|
What |
A way to create
generators (type of iterable you can use to create lazy sequences) without
having to define a function |
|
Example |
(expression for item in
iterable) |
|
Where |
Use them when you want
to produce a sequence of values, one at a time, on demand |
|
Why? |
Memory is saved as items
are only produced as required |
Comments
Post a Comment