python - return two lists from a list comprehension -- performance -


In my program, I am getting all the directories and files ( running ) Write all dictionaries as keys for a dictionary in the form of keys, get the path as values, then get a keyword from the interface ( tk.Entry ) and enter two lists Return all matches from I'll show them ( tk.Listbox ) and open the selected one ( win32shell ).

I used to make two lists with one understanding. In the comments, it says, "The calculation of just two separate lists is simple and perhaps faster." So thats confuses me to use one because this program will be run through ~ 3TB data which I do not have yet so I can not run and can not see which will be faster.

This is my minimum code, I have removed the interface and defined keyword and path through the keywrd , folder variable, respectively.

  import os import sqlite3 audio_ext = [".mp3", ".mp4", "etc ..."] folder = "C: \\ user \\ Lafexlos \\ music \" keyboard \ "= "Mo" ## The search keyword which I usually receives from the user by entry conn = sqlite3.connect (": memory:") data = conn.cursor () data.execute ("If the table does not exist then the table Make "Ocelid" Files in Roots, Dior, OS Walk (Folder) for the Inam: "+" Items. Split (".") [- 1]. Audio_ext in flower (): #Abau line is not friendly to the eyes, but only the file's Execute checks data. Execute ("Audio in INSERT or IGNORE \" (path, file name) value (?,?) ", (Roots, items)) rows = {} Musics = data.execute (" Select from Audio " ") [Lines .update ({row [1]: line [0]}) # # This is the option for the line in music 1. Using Zip to create two results of lists , For path = (* [([K, V) * for Kashmir, in V lines .it () if keywrd in k]) # This option is 2. Assess the same list twice for the result = [( K, V) in lines. Ifts (), for the key k] path = [v for (k, v) lines.items () print key "RDR" in Key K in print ("result:", result) print ("\ n \ n Path: ", path)   

As I mentioned above, my question is, what will be working fast in large quantities of data?

Use zip () :

  Results, path = zip (* (Kashmir, V) in Kashmir, in lines V. Items (if key in Kashmir))   

In this same phase Will produce two lists. Is optional for a loop :

  results = [] path = [] (in K, V) items in lines ( ): If Key in Kashmir: results.append (k) paths.append (v)   

If you want to create a list then the list's criteria are big is ; If you need many from the same loop, then just use the loop.

However, since this data comes from the SQLite query, your best bet would be to limit the SQLite rows

  data. Execute ("Choose from the audio if you like file name?", ('% {}%'. Format (keywrd),))   

your line dictionary The dictionary is made more efficiently with the understanding:

  musics = data.execute ("select from audio") line = {line [1]: row for line in movie [0 ]}   

or more specific query By using and direct loop on cursor:

  Data.execute ("selection path, file name by WHERE file name?", ('% {}%'. Format (keywrd) ,) Wildcard on both sides against a string with path, result = zip (* data)   

like % The result results in a in test in Python; If the keyword name is contained in the file name in line matches.

There is no need to make any arbitrator dictionary anymore.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -