ppotatomato
ppotatomato

Reputation: 57

'tuple' object has no attribute 'loc' in def

I am working on an assignment regarding map_reduce, but have some issues when running the function def.

a = [((1,1/4), [2,3,4]), ((2, 1/4), [3,4]), ((3,1/4), [1,4]), ((4,1/4),[2])]

accessing the elements outside of the function works well:

Result from accessing element

So I moved forward to put them into a function:

def mapper_PR(Data): 
  node = Data[0][0][0]
  pr = Data[0][0][1]
  dest = Data[0][1]
  degree = len(dest)

  return [[i, pr/degree] for i in dest]

import defs
mapped_values = map(defs.mapper_PR, a)
mapped_values

partition_value = list(itertools.chain(*mapped_values))

However, when I define it as a function and import the .py file back to google collab, it starts to have problem

This is the error code I received:

error code

How can I rectify this issue?

Upvotes: 0

Views: 331

Answers (1)

Himanshu Pingulkar
Himanshu Pingulkar

Reputation: 336

Modifing the code solved the problem.

import itertools

def mapper_PR(Data): 
  node = Data[0][0][0]
  pr = Data[0][0][1]
  dest = Data[0][1]
  degree = len(dest)

  return ([i, pr/degree] for i in dest)


a = [((1,1/4), [2,3,4]), ((2, 1/4), [3,4]), ((3,1/4), [1,4]), ((4,1/4),[2])]
mapped_values = mapper_PR(a)
mapped_values

partition_value = list(itertools.chain(*mapped_values))
partition_value

Upvotes: 1

Related Questions