Python performance: set vs list
15th August 2011
Sometimes there is a need to be sure that no identifier is processed twice – for example, when parsing a file into a database, with file potentially containing duplicate records. An obvious solution is to properly wrap the DB insertion code into try…except block, and process duplicate primary ID exceptions. Another, sometimes more desired solution is to maintain a set/list of processed IDs internally, and check against that list prior to attempting the insertion of anything. So is it a set or a list?
There are already quite a few internet resources discussing “python set vs list”, but probably the simplest while elegant way to test that is below.
Read the rest of this entry »
Posted in Notepad, Programming, Python | 1 Comment »