Python Generator Vs Comprehension And Pass By Reference Vs Value
I have some code that iterates over a string and produces a list of objects from the string, which I'm calling an instance. It looks something like this. from collections import de
Solution 1:
It seems that the issue has to do with how I was initiating my data. I was initiating a defaultdict as a member of the class:
classmyClass:
self.data = defaultdict(str)
def__init__(self, data):
for i, instance inenumerate(data.split('\n')):
# Do something...
self.data[i] = instance
I changed it to this:
classmyClass:
def__init__(self, data):
self.data = defaultdict(str)
for i, instance inenumerate(data.split('\n')):
# Do something...
self.data[i] = instance
And that fixed my problem. Would be interested to hear if anyone knows why.
Post a Comment for "Python Generator Vs Comprehension And Pass By Reference Vs Value"