diff --git a/advanced-iterators.html b/advanced-iterators.html index 96f1314..472ae72 100755 --- a/advanced-iterators.html +++ b/advanced-iterators.html @@ -168,7 +168,7 @@ if __name__ == '__main__': AssertionError >>> assert 2 + 2 == 5, "Only for very large values of 2" Traceback (most recent call last): - File "", line 1, in <module> + File "<stdin>", line 1, in <module> AssertionError: Only for very large values of 2
  1. The assert statement is followed by any valid Python expression. In this case, the expression 1 + 1 == 2 evaluates to True, so the assert statement does nothing. @@ -178,7 +178,7 @@ AssertionError: Only for very large values of 2

    Therefore, this line of code: -

    assert len(unique_characters) <= 10, 'Too many letters'
    +
    assert len(unique_characters) <= 10, 'Too many letters'

    …is equivalent to this: @@ -250,7 +250,7 @@ gen = ord_map(unique_characters) (3, 2) >>> next(perms) Traceback (most recent call last): - File "<stdin>", line 1, in + File "<stdin>", line 1, in <module> StopIteration

    1. The itertools module has all kinds of fun stuff in it, including a permutations() function that does all the hard work of finding permutations. @@ -279,7 +279,7 @@ StopIteration ('C', 'B', 'A') >>> next(perms) Traceback (most recent call last): - File "<stdin>", line 1, in + File "<stdin>", line 1, in <module> StopIteration >>> list(itertools.permutations('ABC', 3)) [('A', 'B', 'C'), ('A', 'C', 'B'), @@ -582,8 +582,8 @@ NameError: name '__import__' is not defined >>> eval("__import__('subprocess').getoutput('rm -rf /')", ... {"__builtins__":None}, {}) Traceback (most recent call last): - File "<stdin>", line 1, in - File "<string>", line 1, in + File "<stdin>", line 1, in <module> + File "<string>", line 1, in <module> NameError: name '__import__' is not defined
      1. To evaluate untrusted expressions safely, you need to define a global namespace dictionary that maps "__builtins__" to None, the Python null value. Internally, the “built-in” functions are contained within a pseudo-module called "__builtins__". This pseudo-module (i.e. the set of built-in functions) is made available to evaluated expressions unless you explicitly override it.