Iterator

An iterator is an object that enables traversing a container, such as a list.

Python Example

# Range iterator.
for number in range(0, 10):
    print(str(number))

# Collection iterator.
for word in ['one', 'two', 'three']:
    print(word)

# Dictionary iterator using the iteritems() method.
dictionary = {'one': 1, 'two': 2, 'three': 3}
for key, value in dictionary.iteritems():
    print(key, value)

# String iterator.
for character in 'my string':
    print(character)

# Iteration using while.
count = 0
while count < 10:
    print(count)
    count += 1