b = Operator.itemgetter (1) defines function B, which is used to get the value of the 1th field passed into the list
You can use B as the key for the sort function. As the basis for sorting.
Adn_app_data_map is a dictionary.
For key, App_arr in Adn_app_data_map.items ():
App_arr.sort (Key=operator.itemgetter (' click '), Reverse=true)
App_arr = App_arr[:3]
Keys = Key.split (' # ')
Category = Keys[0]
ad_network_id = keys[1]
ad_id = keys[2]
For apps in App_arr:
dimension_values = category + ' # ' + app[' app_id ' + ' # ' + ad_network_id + ' # ' + ad_id
Record = app[' campaign_id ' + ', ' + Adn_ad_category_app_report + ', ' + dimension_values + ', ' + app[' impression '] + \
', ' + str (app[' click ') + ', ' + app[' impression_cost '] + ', ' + app[' click_cost '] + ' \ n '
Csv.writelines (Record)
Python's Operator.itemgetter (' click ') is used to define the function that gets the ' click ' entry