python sieve using dictionaries