Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing lists of lists and writing certain elements into a new list
    primarykey
    data
    text
    <p>It looks like this question has been asked dozens of times, but none of the answers have helped me out, so I'm afraid I'm asking it again (please don't hate me!). I have two lists of lists: </p> <pre><code>amm = [['0005FC66DF', '4403'", ',\n'], [" ['0001C52E02', '4406'", ',\n'],etc] </code></pre> <p>and</p> <pre><code>data = [['07/11/2012', '09:53:36', 'Thing', '#0F', '0006E7895B', 'T', 'U\n'], ['05/13/2012', '09:54:27', 'Thing', '#0F', '0006E3DADA', 'T', 'U\n'], etc]. </code></pre> <p>I want to see if the 5th element in a list in data is the same as the first element in a list in amm, and if so, I want to write the list from data to a new list of lists, amv. I have tried EVERYTHING. I started with</p> <pre><code>for i in data: if data[i][4] in amm: amv[i].append(i) </code></pre> <p>which didn't write anything to amv, so I tried</p> <pre><code>amv=[item for item in data if item[4] in[items for items in amm]] </code></pre> <p>which had the same problem, so I tried</p> <pre><code> for i in data: for j in amm: if i[4] == j[0]: amv.append(j) </code></pre> <p>and a million (probably slightly more accurate) variations on these themes. This should be such a simple thing to do but it's just not working for me. Any help would be very, very much appreciated. Thanks in advance!</p> <p>EDIT Sorry this wasn't very clear. What I'm trying to do is write a new list (amv) that contains all the lists in data that have their fifth element appear in amm. All of the scripts I've shown haven't added anything to the new list, amv. amv has always stayed empty, and I can't figure out why..</p>
    singulars
    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