0

So below is my code: I am getting none type object is not iterable error as append is not happening.

result_list_haops=[]
each_result={'name': 'ads-scin-tracking', 'monitoringGroup': 'HAOPS', 'azkabanInstance': 'lva1-war-waraz01', 'project': 'ads-metrics-pipeline', 'subscribers': ['ads-relevance@linkedin.com'], 'invalid_attribute': 'teamAskAlias', 'link': 'https://intake2.corp.linkedin.com:8767/#/flows/view/lva1-war-waraz01/ads-metrics-pipeline-ads-scin-tracking'}
group = each_result['monitoringGroup']
        self.log.debug(group)
if group == "HAOPS":
    result_list_haops = result_list_haops.append(each_result)

Later in my code,

result_grouped_by = sorted(result_list,key=itemgetter('subscribers')) 

it throws Nonetype object is not iterable.

I am unable to find what is it I am doing wrong here.

Error i am getting: Nonetype object is not iterable

Desired behaviour:

result_list_haops=[{'name': 'ads-scin-tracking', 'monitoringGroup': 'HAOPS', 'azkabanInstance': 'lva1-war-waraz01', 'project': 'ads-metrics-pipeline', 'subscribers': ['ads-relevance@linkedin.com'], 'invalid_attribute': 'teamAskAlias', 'link': 'https://intake2.corp.linkedin.com:8767/#/flows/view/lva1-war-waraz01/ads-metrics-pipeline-ads-scin-tracking'}]

Please help me.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
user1795999
  • 301
  • 2
  • 5
  • 15
  • Hint: Notice how the code (correctly) **does not** say `result_grouped_by = result_list.sort(key=itemgetter('subscribers'))`? What would go wrong if you tried that instead? Now, do you see why the same logic would apply to `.append` as does to `.sort`? (What do those two methods have in common?) – Karl Knechtel Sep 13 '22 at 20:07

1 Answers1

1

append doesn't have return statement so it returns default None, which changes result_list_haops from list to None. Don't use assignment

if group == "HAOPS":
    result_list_haops.append(each_result)
Guy
  • 46,488
  • 10
  • 44
  • 88