Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm unaware of a library doing what you ask (but I only glanced at the <code>sqldf</code> documentation), however nothing of what you asked really requires a library, they are one-liners in python (and you could of course abstract the functionality creating a function rather than a simple list comprehension...)</p> <blockquote> <p>Set A= {1,0}, a list B = [[1,1],[2,3]]. I would like to find all rows in B where the second column is one of the values in A.</p> </blockquote> <pre><code>&gt;&gt;&gt; a = set([1, 0]) &gt;&gt;&gt; b = [[1,1],[2,3]] &gt;&gt;&gt; [l for l in b if l[1] in a] [[1, 1]] </code></pre> <blockquote> <p>I have 2 CSV files. I want to find out all the rows where the values of some column from the two files match.</p> </blockquote> <pre><code>&gt;&gt;&gt; f1 = [[1, 2, 3], [4, 5, 6]] &gt;&gt;&gt; f2 = [[0, 2, 8], [7, 7, 7]] &gt;&gt;&gt; [tuple_ for tuple_ in zip(f1, f2) if tuple_[0][1] == tuple_[1][1]] [([1, 2, 3], [0, 2, 8])] </code></pre> <hr> <p><strong>EDIT:</strong> If memory usage is a problem you should use generators instead of lists. For example:</p> <pre><code>&gt;&gt;&gt; zip(f1, f2) [([1, 2, 3], [0, 2, 8]), ([4, 5, 6], [7, 7, 7])] </code></pre> <p>but using generators:</p> <pre><code>&gt;&gt;&gt; import itertools as it &gt;&gt;&gt; gen = it.izip(f1, f2) &gt;&gt;&gt; gen &lt;itertools.izip object at 0x1f24ab8&gt; &gt;&gt;&gt; next(gen) ([1, 2, 3], [0, 2, 8]) &gt;&gt;&gt; next(gen) ([4, 5, 6], [7, 7, 7]) </code></pre> <p>And for the data source:</p> <pre><code>&gt;&gt;&gt; [line for line in f1] [[1, 2, 3], [4, 5, 6]] </code></pre> <p>translate as generator as:</p> <pre><code>&gt;&gt;&gt; gen = (line for line in f1) &gt;&gt;&gt; gen &lt;generator object &lt;genexpr&gt; at 0x1f159b0&gt; &gt;&gt;&gt; next(gen) [1, 2, 3] &gt;&gt;&gt; next(gen) [4, 5, 6] </code></pre>
 

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