Note that there are some explanatory texts on larger screens.

plurals
  1. POPython, removing whole list if it contains a matching tuple
    primarykey
    data
    text
    <p>I hope this hasn't been asked before but it's hard for me to put into words what it is I'm trying to do!</p> <p>It might be easier if I explain my input, and desired output</p> <pre><code>l1 = [[(14, 'h'), (14, 'd')], [(14, 'h'), (14, 'c')], [(14, 'h'), (14, 's')], [(14, 'd'), (14, 'c')], [(14, 'd'), (14, 's')], [(14, 'c'), (14, 's')], [(13, 'h'), (13, 'd')], [(13, 'h'), (13, 'c')], [(13, 'h'), (13, 's')], [(13, 'd'), (13,'c')], [(13, 'd'), (13, 's')], [(13, 'c'), (13, 's')], [(12, 'h'), (12, 'd')], [(12, 'h'), (12, 'c')], [(12, 'h'), (12, 's')], [(12, 'd'), (12, 'c')], [(12, 'd'), (12, 's')], [(12, 'c'), (12, 's')]] l2 = [(13,'h'),(13,'d'),(14,'c'),(14,'s'),(14,'h')] </code></pre> <p>So this first list, l1, is a list of lists, each list is a poker hand of 2 cards.</p> <p>Basically what I'm trying to do is if a card is in l2, the hand in l1 needs to be removed. So the entry [(14,'d'),(14,'c')] needs to be removed from l1 because (14,'c') is in l2-- even though (14,'d') isn't in l2.</p> <p>The desired output from this example should be,</p> <pre><code>[[(13, 'c'), (13, 's')], [(12, 'h'), (12, 'd')], [(12, 'h'), (12, 'c')], [(12, 'h'), (12, 's')], [(12, 'd'), (12, 'c')], [(12, 'd'), (12, 's')], [(12, 'c'), (12, 's')]] </code></pre> <p>I thought about iterating over all the tuples inside l1 and removing them if they're in l2, then afterwards go back and iterate over the lists in l1 and remove any without len == 2. This doesn't seem like the best way to go, though.</p> <p>Any thoughts?</p> <p>ManyTIA!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload