How can I make method each in Python like its in Ruby? Is that possible, am really do!
In Ruby its looks like:
%w[1 2 3 4].each { |i| puts i}
In Python we have for:
for i in [1, 2, 3]: print(i)
So, I want to make each method in Python, here is my code:
class Iter:
def each(self, data):
processed = data.__iter__()
yield processed.__next__()
if __name__ == "__main__":
test = Iter()
print(list(test.each([1, 2, 3])))
Its working not as each, its return only first element. Thx in advance!