When using itertools unable to retrieve data issue - noattribute _getitem_


Please help me in this issue?


split is a function. you should always use ( ) for functions. you have used [ ] in your code. [ ] is used in python collections to fetch elements. You can try running the program again.



Thanks Sunil for your response. This is what you asked me to change right? I got the same issue.

Please suggest me if I haven’t done correctly.



As you are slicing using [0:10] you should return list from the function. currently you are returning itertool grouper object and slicing it which is wrong. Return List(orderItemsPerOrderId)

Below code worked for me -

def revenuePerOrder(orderItems):
orderItemsMap = it.imap(lambda oi: (int(oi.split(",")[1]), float(oi.split(",")[4])),orderItems)
ordeItemsPerOrderId = it.groupby(sorted(orderItemsMap), lambda k:k[0])
return list (ordeItemsPerOrderId)



check this code i am able to view the output


@Sunil_Itversity - You are using map not iter tools imap. The code that @jeevan_kishore trying is with itertool imap
map is a collection that you can loop over but not imap which is an itertool grouper object


Thanks both of you for your quick reply. It worked for me :slight_smile: