Hi,
if you know the Python internals, here is a newbie question for you.
If I have a list with 100 elements, each element being a long string,
is it more efficient to maintain it as a dictionary (with a key = a
string from the list and value = None) for the purpose of insertion
and removal?
Basically, if Python really implements lists as linked lists but
dictionaries as hash tables, it may well be that hashing a key takes
negligible time as compared to comparing it against every list
element.
Oh and here is (as a non-sequiter) something I don't understand
either:[color=blue][color=green][color=darkred]
>>> x = ([],)
>>> x[0] += ['something'][/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment[color=blue][color=green][color=darkred]
>>> x[/color][/color][/color]
(['something'],) <---- complained but did it anyway??[color=blue][color=green][color=darkred]
>>> x[0].append('and another thing') <------- no complaint!
>>> x[/color][/color][/color]
(['something', 'and another thing'],)
if you know the Python internals, here is a newbie question for you.
If I have a list with 100 elements, each element being a long string,
is it more efficient to maintain it as a dictionary (with a key = a
string from the list and value = None) for the purpose of insertion
and removal?
Basically, if Python really implements lists as linked lists but
dictionaries as hash tables, it may well be that hashing a key takes
negligible time as compared to comparing it against every list
element.
Oh and here is (as a non-sequiter) something I don't understand
either:[color=blue][color=green][color=darkred]
>>> x = ([],)
>>> x[0] += ['something'][/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment[color=blue][color=green][color=darkred]
>>> x[/color][/color][/color]
(['something'],) <---- complained but did it anyway??[color=blue][color=green][color=darkred]
>>> x[0].append('and another thing') <------- no complaint!
>>> x[/color][/color][/color]
(['something', 'and another thing'],)
Comment