Be kind, I'm still learning python (but getting better). I've looked at the other posts regarding generators, and haven't found an answer to my specific question. Sorry, if I missed it.
So I am writing a method that acts as a generator. I can make it work, but not the way I want it to. I'm trying to understand generators.
If I write the following:
def genfunc(self):
"""
self.some_lst is defined in __init__ as a list of tuples. e.g [(1,2),(2,3)]
"""
yield (x for x in self.some_lst)
I get
Line 73: TypeError: '<invalid type>' does not support indexing
however, if I write it as:
def genfunc()
"""
self.some_lst is defined in __init__ as a list of tuples. e.g [(1,2),(2,3)]
"""
for x in self.some_lst:
yield x
Everything works fine.
Two questions: 1. What am I fundamentally missing about generators? and 2. Is there a way to write this in one line as I tried (but failed) to do?
I know there are some SOers just waiting to help this newb out. Thanks in advance.