[Tutor] Directory operation: why so darn slow?

Johannes Graumann graumann@its.caltech.edu
Sat Nov 2 21:36:02 2002


--=.BICYX0?v2xFmzg
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Hello,

I have a class that spits out a dictionary ('contrast.data()') and I have two major problems with it:

1) the operation represented by the snippet below is ridiculisly slow (didn't use to be - before I had a several level deep dictionary) - is there anything I can do about that?

repres_filtered = {}
for dataset in contrast.data()['conform'].keys():
 seqcov_count = 0
  for element in contrast.data()['conform'][dataset]['seqcov']:
   if re.match(r"\d+",element):
    seqcov_count = seqcov_count + 1
  if not seqcov_count < repres:
   repres_filtered[dataset]=contrast.data()['conform'][dataset]

2) does the fact that the dictionary is created by the class imply that I can not change it (delete it)? I would prefer to do something like

for dataset in contrast.data()['conform'].keys():
 seqcov_count = 0
  for element in contrast.data()['conform'][dataset]['seqcov']:
   if re.match(r"\d+",element):
    seqcov_count = seqcov_count + 1
  if not seqcov_count < repres:
   del contrast.data()['conform'][dataset]

Thanks for any hint!

Joh

--=.BICYX0?v2xFmzg
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE9xIv8JSKujSMUwjMRAuj8AKCcseQN7878SJRhEjBzKyZgRc96JwCaAkA0
nTwfPnEdx/aRuhYrn4BjwHA=
=H52X
-----END PGP SIGNATURE-----

--=.BICYX0?v2xFmzg--