Solution 1

``````import string
import random

def __init__(self, available_chars=None, length=8):
if not available_chars:
available_chars = list(
string.ascii_lowercase + string.digits + string.punctuation)

self.available_chars = available_chars
self.length = length

def __iter__(self):
return self

def next(self):  # use __next__ in Python 3.x
return ''.join([
random.choice(self.available_chars) for _ in range(self.length)])

__next__ = next
``````

Write a simple random password generator using iterators. The generator can accept two parameters:
`available_chars`: The characters to use to generate the password. OPTIONAL. Default: A set of lowercase characters, digits and symbols. (hint, check the `string` module)
`length`: The length of the password. OPTIONAL. Default: 8

``````pass_generator = SimplePasswordGenerator()
next(pass_generator)  # %58a\$d8a (length=8)

next(pass_generator)  # '%58a\$d8a' (length=8)

next(pass_generator)  # 'abba'
``````

Note: Make sure you implement the iterator in a way compatible with both Python 2 and Python 3

### Test Cases

test respects passed length -

``````def test_respects_passed_length():
length_2_it = iter(length_2)
assert len(next(length_2_it)) == 2

length_4_it = iter(length_4)
assert len(next(length_4_it)) == 4

length_16_it = iter(length_16)
assert len(next(length_16_it)) == 16
``````

test uses available chars -

``````def test_uses_available_chars():