0
votes

Suppose I have a string as an iterator.

a = iter("hello")

a.next() returns the first letter h. Is there a way to easily get , for example the first 3 letters using the same method without looping it 3 times?

1
iterator.next() doesn't exist in Python 3. It was replaced with .__next__(). Which version are you actually using?wjandrea

1 Answers

-2
votes

Here is a possible solution

a = "hello"

b, c, d = a[0:3]

print(b, c, d)