When using itertools unable to retrieve data issue - noattribute _getitem_


#1

Please help me in this issue?


#2

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.

Regards,
Sunil


#3

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.

Thanks


#4

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)


#5

@jeevan_kishore

check this code i am able to view the output


#6

@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


#7

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