0

I'm using list comprehension to get counts of value of a key in each dictionary yielded by a generator, but I'm not sure if I'm using the right syntax, because I get 0 results:

ln_is = [d['url'] for d in generator if d['url_source'] is '"http://ln.is']

I am sure that the dictionaries in this generator has those values.

halo09876
  • 2,725
  • 12
  • 51
  • 71
  • 2
    https://stackoverflow.com/questions/2988017/string-comparison-in-python-is-vs – cs95 Dec 07 '18 at 03:32
  • 4
    `is` should never be used to compare strings, unless you're a bona expert playing deep, deep tricks. Use `==` instead I bet it will work. – Tim Peters Dec 07 '18 at 03:32
  • @TimPeters I also wonder because some the urls are None? Should I do ln_is = [d['url'] for d in generator if d['url_source'] is not None and '"http://ln.is'] – halo09876 Dec 07 '18 at 03:35
  • 1
    `None` never compares equal to a string, nor does an attempt raise an exception - `None` just isn't an issue here. – Tim Peters Dec 07 '18 at 03:38

0 Answers0