python - how to delete a key in a list of dicts? -


def get_all_cust_info():     """function displays data list of dict of base  data"""     reader = csv.dictreader(open("base data.csv", "rb"))     all_rows = list()     row in reader:     all_rows.append(row)     return all_rows 

first line output of get_all_cust_info().

   [{'totcust': '2', 'delfee': '1308', 'bskt_bnd': '0', 'distribution ': '>1', 'totords': '199', 'netsales': '1851'}, .......]  

i want create new function deletes keys('delfee' , 'netsales') , add new key 'order value'.this have done

    def cust_state():         s = get_all_cust_info()         d in s:             if d.has_key('delfee'):                del d['delfee']                print s   

but getting error.

  attributeerror: 'list' object has no attribute 'has_key' 

would appreciate on this.

if s.has_key('delfee'): 

should be:

if d.has_key('delfee'): 


def cust_state():         s = get_all_cust_info()         d in s:             if 'delfree' in d:                 del d['delfree']             if 'netsales' in d:                 del d['netsales']             d['ordervalue'] =         return s 

Comments