I have the following code:
neig = []
for _ in xrange(number):
r = random.randint(0,self._tam-1)
s = random.randint(0,self._tam-1)
neig.append([r,s, self.deltaC(r, s)])
I am trying to get rid of the for loop using map, a generator or something to optimize the build of the list. I've checked this answer, but in my case I need to give values to the elements.
Would it be possible to use a generator and delay the call to deltaC? I think using map is not possible because the body of the loop has more than one statement.
deltaC? When will you need that value; will you need it for all values inneig, and more than once?deltaClater in the program. If I have an element of this list of list [1,2,deltaC(1,2)], ¿Could it be evaluate later?. Maybe I misunderstood the concept of generators. If delay the call is not possible, How could I generate this array more efficiently?randsin the list, then calldeltaC(r, s)where you need that value. What is more important - run time or memory use?deltaCreturns a very huge structure, or thatnumberis very large, such that it is not feasible to retain the whole list into memory? If this is the case, generators might help.