def perm(l):
# Compute the list of all permutations of l
if len(l) <= 1:
return [l]
r = []
for i in range(len(l)):
s = l[:i] + l[i+1:]
p = perm(s)
for x in p:
r.append(l[i:i+1] + x)
return r
def perm(l):
# Compute the list of all permutations of l
if len(l) <= 1:
return [l]
r = []
for i in range(len(l)):
s = l[:i] + l[i+1:]
p = perm(s)
for x in p:
r.append(l[i:i+1] + x)
return r
>>> print('Hello') # this is indented
File "<stdin>", line 1
print('Hello') # this is indented
^
IndentationError: unexpected indent
>>> age = 10
>>> can_drive = None
>>>
>>> if age >= 18:
... print('You can drive')
... can_drive = True # incorrectly indented
File "<stdin>", line 3
can_drive = True # incorrectly indented
^
IndentationError: unexpected indent
>>> print('Hello') # simply unindent the line
Hello
>>> age = 10
>>> can_drive = None
>>>
>>> if age >= 18:
... print('You can drive')
... can_drive = True # indent this line at the same level.
...
>>> if True:
...
File "<stdin>", line 2
^
IndentationError: expected an indented block
>>> names = ['Sarah', 'lucy', 'michael']
>>> for name in names:
... print(name)
File "<stdin>", line 2
print(name)
^
IndentationError: expected an indented block
>>> if True:
... # TODO
...
File "<stdin>", line 3
^
IndentationError: expected an indented block
>>> names = ['Sarah', 'lucy', 'michael']
>>> for name in names:
... print(name) # The for loop body is Now correctly indented.
...
Sarah
lucy
michael
def f(arg): pass # a function that does nothing (yet)
class C: pass # a class with no methods (yet)
>>> if True:
... pass # We don't want to define a body.
...
>>>
>>> if True:
... if True:
... print('yes')
... print()
File "<stdin>", line 4
print()
^
IndentationError: unindent does not match any outer indentation level
>>> if True:
... if True:
... print('yes')
... print() # indentation level Now matches former statement's level.
...
yes
>>>
>>> if True:
... if True:
... print()
... print()
... print()
File "<stdin>", line 5
print()
^
TabError: inconsistent use of tabs and spaces in indentation
>>> if True:
... if True: # tab
... pass # tab, then 4 spaces
...
>>>
>>> if True:
... pass # tab
... pass # 4 spaces
File "<stdin>", line 3
pass # 4 spaces
^
IndentationError: unindent does not match any outer indentation level
if True:
pass
pass # oops! this statement should be indented!.
else:
pass
Traceback (most recent call last):
File "python", line 4
else:
^
SyntaxError: invalid Syntax