Initial Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

LLM Generation

Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

Output

To create a Python function named `dedent(str)` that maximally de-dents a given string of Python code, you can follow the approach below. This function will calculate the minimum indentation level of non-empty lines and remove that level of indentation from every line, effectively maximizing the de-indentation of the given code. Here's how you could implement it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Calculate the minimum indentation (excluding empty lines)
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line:  # Only consider non-empty lines
            indent_level = len(line) - len(stripped_line)
            if min_indent is None or indent_level < min_indent:
                min_indent = indent_level
    
    # If all lines are empty or the input is empty, return the original string
    if min_indent is None:
        return code_str
    
    # De-indent each line by the minimum indentation found
    deindented_lines = [line[min_indent:] if len(line) >= min_indent else line for line in lines]
    
    # Re-join the lines into a single string to return
    return '\n'.join(deindented_lines)

# Example usage:
if __name__ == "__main__":
    code = """
        def hello_world():
            print("Hello, world!")
            if True:
                print("Indeed, true.")
    """
    
    print(dedent(code))
This function works by first determining the minimum amount of leading whitespace across all non-empty lines. It then subtracts this amount of whitespace from each line. The `lstrip()` method is used to remove leading whitespace when calculating indentation levels to ensure we only consider the leading spaces/tabs that are part of the code's indentation, excluding empty lines. The `dedent()` function provided above can handle mixed indentation (spaces and tabs) but adheres to Python's indentation rules, which discourage mixing tabs and spaces. For real-world applications, it's recommended to follow PEP 8 guidelines and use spaces consistently for indentation.

Extract Code

I extracted the following code from that output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Calculate the minimum indentation (excluding empty lines)
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line:  # Only consider non-empty lines
            indent_level = len(line) - len(stripped_line)
            if min_indent is None or indent_level < min_indent:
                min_indent = indent_level
    
    # If all lines are empty or the input is empty, return the original string
    if min_indent is None:
        return code_str
    
    # De-indent each line by the minimum indentation found
    deindented_lines = [line[min_indent:] if len(line) >= min_indent else line for line in lines]
    
    # Re-join the lines into a single string to return
    return '\n'.join(deindented_lines)

# Example usage:
if __name__ == "__main__":
    code = """
        def hello_world():
            print("Hello, world!")
            if True:
                print("Indeed, true.")
    """
    
    print(dedent(code))

Run Code Interpreter

Running the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Calculate the minimum indentation (excluding empty lines)
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line:  # Only consider non-empty lines
            indent_level = len(line) - len(stripped_line)
            if min_indent is None or indent_level < min_indent:
                min_indent = indent_level
    
    # If all lines are empty or the input is empty, return the original string
    if min_indent is None:
        return code_str
    
    # De-indent each line by the minimum indentation found
    deindented_lines = [line[min_indent:] if len(line) >= min_indent else line for line in lines]
    
    # Re-join the lines into a single string to return
    return '\n'.join(deindented_lines)

# Example usage:
if __name__ == "__main__":
    code = """
        def hello_world():
            print("Hello, world!")
            if True:
                print("Indeed, true.")
    """
    
    print(dedent(code))





answer = dedent('''    print("hello")
    print("world")

    if True:
        print("true")
    else:
        print("false")''')
expected = """print("hello")
print("world")

if True:
    print("true")
else:
    print("false")"""
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
print('All tests passed')
And got the output:
1
2
3
4
5
def hello_world():
    print("Hello, world!")
    if True:
        print("Indeed, true.")</p>
<p>All tests passed

Substring Evaluation

Testing if the previous output contains the string All tests passed: True

Initial Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

LLM Generation

Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

Output

To write a Python function `dedent(str)` that takes a string of Python code and de-dents it maximally, you can follow these steps. The objective is to determine the minimum indentation level of all non-empty lines and then remove this amount of leading whitespace from every line. Here is how you can implement it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation that is not zero
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        # Skip empty lines
        if not stripped_line:
            continue
        indent = len(line) - len(stripped_line)
        if min_indent is None or indent < min_indent:
            min_indent = indent
    
    # If the code is not indented, return it as is
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent each line by the minimum indentation
    dedented_lines = [line[min_indent:] if len(line.lstrip()) != 0 else line for line in lines]
    
    # Join the lines back together
    dedented_code = '\n'.join(dedented_lines)
    
    return dedented_code

# Example usage
code = """
    def hello_world():
        print("Hello, world!")
    
    hello_world()
"""
dedented_code = dedent(code)
print(dedented_code)
This function works as follows: 1. It splits the input string into lines. 2. It iterates over each line to find the minimum indentation that is not zero, ignoring completely blank lines. 3. If no indentation is found (i.e., the code is already maximally de-dented or consists only of blank/comment lines), it returns the code as-is. 4. Otherwise, it reduces the indentation of each non-empty line by the minimum indentation found. 5. It joins the dedented lines back into a single string and returns it. This implementation assumes that the input string uses consistent indentation (e.g., all spaces or all tabs) and does not mix tabs and spaces for indentation, following the Python style guide (PEP 8).

Extract Code

I extracted the following code from that output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation that is not zero
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        # Skip empty lines
        if not stripped_line:
            continue
        indent = len(line) - len(stripped_line)
        if min_indent is None or indent < min_indent:
            min_indent = indent
    
    # If the code is not indented, return it as is
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent each line by the minimum indentation
    dedented_lines = [line[min_indent:] if len(line.lstrip()) != 0 else line for line in lines]
    
    # Join the lines back together
    dedented_code = '\n'.join(dedented_lines)
    
    return dedented_code

# Example usage
code = """
    def hello_world():
        print("Hello, world!")
    
    hello_world()
"""
dedented_code = dedent(code)
print(dedented_code)

Run Code Interpreter

Running the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation that is not zero
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        # Skip empty lines
        if not stripped_line:
            continue
        indent = len(line) - len(stripped_line)
        if min_indent is None or indent < min_indent:
            min_indent = indent
    
    # If the code is not indented, return it as is
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent each line by the minimum indentation
    dedented_lines = [line[min_indent:] if len(line.lstrip()) != 0 else line for line in lines]
    
    # Join the lines back together
    dedented_code = '\n'.join(dedented_lines)
    
    return dedented_code

# Example usage
code = """
    def hello_world():
        print("Hello, world!")
    
    hello_world()
"""
dedented_code = dedent(code)
print(dedented_code)





answer = dedent('''    print("hello")
    print("world")

    if True:
        print("true")
    else:
        print("false")''')
expected = """print("hello")
print("world")

if True:
    print("true")
else:
    print("false")"""
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
print('All tests passed')
And got the output:
1
2
3
4
def hello_world():
    print("Hello, world!")</p>
<p>hello_world()
All tests passed

Substring Evaluation

Testing if the previous output contains the string All tests passed: True

Initial Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

LLM Generation

Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

Output

To create a Python function named `dedent` that maximally de-dents a given string of Python code, you can follow this approach. The function calculates the minimum indentation level of all non-empty lines and then removes this amount of leading space from each line. It's important to handle tabs and spaces correctly, so for simplicity, this solution will assume spaces are used for indentation. If tabs are mixed in, you might want to preprocess the string to convert tabs to spaces according to your needs. Here's a basic implementation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def dedent(code_str):
    # Split the string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation that is not zero
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line:  # If the line is not empty
            indent = len(line) - len(stripped_line)
            if min_indent is None or indent < min_indent:
                min_indent = indent
    
    # If all lines are empty or the code is not indented, return the original code
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent the lines
    dedented_lines = [(line[min_indent:] if len(line) > min_indent else line) for line in lines]
    
    # Join the lines back together
    return '\n'.join(dedented_lines)

# Example usage
code = """
    for i in range(10):
        print(i)
    print('Done')
"""

dedented_code = dedent(code)
print(dedented_code)

# The output will be:
# for i in range(10):
#     print(i)
# print('Done')
This function works as follows: 1. It splits the input string into lines. 2. It then iterates over these lines to find the smallest non-zero indentation level. 3. It subtracts this minimum indentation from the beginning of each line. 4. Finally, it joins these lines back together into a single string. This implementation assumes the code uses spaces for indentation. Handling tabs (especially mixed tabs and spaces) would require a more complex solution, as you would need to decide on a standard number of spaces per tab for your particular use case.

Extract Code

I extracted the following code from that output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def dedent(code_str):
    # Split the string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation that is not zero
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line:  # If the line is not empty
            indent = len(line) - len(stripped_line)
            if min_indent is None or indent < min_indent:
                min_indent = indent
    
    # If all lines are empty or the code is not indented, return the original code
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent the lines
    dedented_lines = [(line[min_indent:] if len(line) > min_indent else line) for line in lines]
    
    # Join the lines back together
    return '\n'.join(dedented_lines)

# Example usage
code = """
    for i in range(10):
        print(i)
    print('Done')
"""

dedented_code = dedent(code)
print(dedented_code)

# The output will be:
# for i in range(10):
#     print(i)
# print('Done')

Run Code Interpreter

Running the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def dedent(code_str):
    # Split the string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation that is not zero
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line:  # If the line is not empty
            indent = len(line) - len(stripped_line)
            if min_indent is None or indent < min_indent:
                min_indent = indent
    
    # If all lines are empty or the code is not indented, return the original code
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent the lines
    dedented_lines = [(line[min_indent:] if len(line) > min_indent else line) for line in lines]
    
    # Join the lines back together
    return '\n'.join(dedented_lines)

# Example usage
code = """
    for i in range(10):
        print(i)
    print('Done')
"""

dedented_code = dedent(code)
print(dedented_code)

# The output will be:
# for i in range(10):
#     print(i)
# print('Done')





answer = dedent('''    print("hello")
    print("world")

    if True:
        print("true")
    else:
        print("false")''')
expected = """print("hello")
print("world")

if True:
    print("true")
else:
    print("false")"""
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
print('All tests passed')
And got the output: for i in range(10): print(i) print('Done') All tests passed

Substring Evaluation

Testing if the previous output contains the string All tests passed: True

Initial Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

LLM Generation

Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

Output

To write a Python function that de-dents a string of Python code maximally, you can follow these steps: 1. Split the string into lines. 2. Determine the minimum indentation level of all non-blank lines. 3. Subtract this minimum indentation from all non-blank lines to de-dent them. 4. Join the lines back into a single string. Here's how you can implement it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation level, ignoring blank lines
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        # Only process non-blank lines
        if stripped_line:
            indent_level = len(line) - len(stripped_line)
            if min_indent is None or indent_level < min_indent:
                min_indent = indent_level
    
    # If the code is entirely blank lines or just a single line with no indentation
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent all lines by the minimum indentation, ignoring completely blank lines
    dedented_lines = [(line[min_indent:] if line.strip() else line) for line in lines]
    
    # Join the lines back into a single string
    dedented_code = '\n'.join(dedented_lines)
    
    return dedented_code
This function works by first determining the minimum non-zero indentation level across all non-blank lines. It then reduces each line's indentation by this minimum amount. Lines that are completely blank are left untouched to preserve the code's structure and readability. Let's test the function with some Python code:
1
2
3
4
5
6
7
8
9
code = """
    def example_function():
        x = 1
        if x < 5:
            return True
        return False
"""

print(dedent(code))
This should output:
1
2
3
4
5
def example_function():
    x = 1
    if x < 5:
        return True
    return False
The function successfully removes the maximum common indentation, making the code block's first line flush with the left margin.

Extract Code

I extracted the following code from that output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation level, ignoring blank lines
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        # Only process non-blank lines
        if stripped_line:
            indent_level = len(line) - len(stripped_line)
            if min_indent is None or indent_level < min_indent:
                min_indent = indent_level
    
    # If the code is entirely blank lines or just a single line with no indentation
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent all lines by the minimum indentation, ignoring completely blank lines
    dedented_lines = [(line[min_indent:] if line.strip() else line) for line in lines]
    
    # Join the lines back into a single string
    dedented_code = '\n'.join(dedented_lines)
    
    return dedented_code

code = """
    def example_function():
        x = 1
        if x < 5:
            return True
        return False
"""

print(dedent(code))

Run Code Interpreter

Running the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def dedent(code_str):
    # Split the input string into lines
    lines = code_str.split('\n')
    
    # Find the minimum indentation level, ignoring blank lines
    min_indent = None
    for line in lines:
        stripped_line = line.lstrip()
        # Only process non-blank lines
        if stripped_line:
            indent_level = len(line) - len(stripped_line)
            if min_indent is None or indent_level < min_indent:
                min_indent = indent_level
    
    # If the code is entirely blank lines or just a single line with no indentation
    if min_indent is None or min_indent == 0:
        return code_str
    
    # Dedent all lines by the minimum indentation, ignoring completely blank lines
    dedented_lines = [(line[min_indent:] if line.strip() else line) for line in lines]
    
    # Join the lines back into a single string
    dedented_code = '\n'.join(dedented_lines)
    
    return dedented_code

code = """
    def example_function():
        x = 1
        if x < 5:
            return True
        return False
"""

print(dedent(code))





answer = dedent('''    print("hello")
    print("world")

    if True:
        print("true")
    else:
        print("false")''')
expected = """print("hello")
print("world")

if True:
    print("true")
else:
    print("false")"""
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
print('All tests passed')
And got the output: def example_function(): x = 1 if x < 5: return True return False All tests passed

Substring Evaluation

Testing if the previous output contains the string All tests passed: True

Initial Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

LLM Generation

Query

Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.

Output

To write a Python function `dedent(str)` that maximally de-dents a given string of Python code, we need to follow these steps: 1. Split the input string into lines. 2. Determine the minimum non-zero indentation level among all lines that are not blank and not comment lines. 3. Reduce the indentation of each line by this minimum level, taking care to not de-indent lines that are blank or are comments that are not indented more than code. 4. Join the lines back into a single string. Here's how you could implement this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def dedent(code_str):
    """
    De-dents the given string of Python code maximally.
    
    :param code_str: A string containing Python code.
    :return: A string with the Python code de-dented maximally.
    """
    lines = code_str.split('\n')
    min_indent = None

    # Find the minimum indentation
    for line in lines:
        stripped_line = line.lstrip()
        # Skip blank lines and comments
        if stripped_line and not stripped_line.startswith('#'):
            indent = len(line) - len(stripped_line)
            if min_indent is None or indent < min_indent:
                min_indent = indent
    
    # If all lines are blank or comments, or code is already de-dented
    if min_indent is None or min_indent == 0:
        return code_str
    
    # De-indent lines
    deindented_lines = []
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line and not stripped_line.startswith('#'):
            deindented_lines.append(line[min_indent:])
        else:
            # For blank lines or lines that are comments, don't adjust indentation
            deindented_lines.append(line)
    
    return '\n'.join(deindented_lines)

# Example usage:
code = """
    def example_function():
        # This is an indented comment
        print("Hello, world!")
    # This comment is not indented
"""
print(dedent(code))
This function works by first determining the minimum indentation level that needs to be removed from all lines (ignoring blank lines and comment lines that don't follow the indentation rules of the code). Then, it reduces the indentation of each line by this amount. For blank lines or lines that are purely comments (with no preceding spaces or with indentation less than the minimum indentation level found), it doesn't adjust the indentation, preserving the original structure of the code.

Extract Code

I extracted the following code from that output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def dedent(code_str):
    """
    De-dents the given string of Python code maximally.
    
    :param code_str: A string containing Python code.
    :return: A string with the Python code de-dented maximally.
    """
    lines = code_str.split('\n')
    min_indent = None

    # Find the minimum indentation
    for line in lines:
        stripped_line = line.lstrip()
        # Skip blank lines and comments
        if stripped_line and not stripped_line.startswith('#'):
            indent = len(line) - len(stripped_line)
            if min_indent is None or indent < min_indent:
                min_indent = indent
    
    # If all lines are blank or comments, or code is already de-dented
    if min_indent is None or min_indent == 0:
        return code_str
    
    # De-indent lines
    deindented_lines = []
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line and not stripped_line.startswith('#'):
            deindented_lines.append(line[min_indent:])
        else:
            # For blank lines or lines that are comments, don't adjust indentation
            deindented_lines.append(line)
    
    return '\n'.join(deindented_lines)

# Example usage:
code = """
    def example_function():
        # This is an indented comment
        print("Hello, world!")
    # This comment is not indented
"""
print(dedent(code))

Run Code Interpreter

Running the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def dedent(code_str):
    """
    De-dents the given string of Python code maximally.
    
    :param code_str: A string containing Python code.
    :return: A string with the Python code de-dented maximally.
    """
    lines = code_str.split('\n')
    min_indent = None

    # Find the minimum indentation
    for line in lines:
        stripped_line = line.lstrip()
        # Skip blank lines and comments
        if stripped_line and not stripped_line.startswith('#'):
            indent = len(line) - len(stripped_line)
            if min_indent is None or indent < min_indent:
                min_indent = indent
    
    # If all lines are blank or comments, or code is already de-dented
    if min_indent is None or min_indent == 0:
        return code_str
    
    # De-indent lines
    deindented_lines = []
    for line in lines:
        stripped_line = line.lstrip()
        if stripped_line and not stripped_line.startswith('#'):
            deindented_lines.append(line[min_indent:])
        else:
            # For blank lines or lines that are comments, don't adjust indentation
            deindented_lines.append(line)
    
    return '\n'.join(deindented_lines)

# Example usage:
code = """
    def example_function():
        # This is an indented comment
        print("Hello, world!")
    # This comment is not indented
"""
print(dedent(code))





answer = dedent('''    print("hello")
    print("world")

    if True:
        print("true")
    else:
        print("false")''')
expected = """print("hello")
print("world")

if True:
    print("true")
else:
    print("false")"""
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
print('All tests passed')
And got the output: def example_function(): # This is an indented comment print("Hello, world!") # This comment is not indented All tests passed

Substring Evaluation

Testing if the previous output contains the string All tests passed: True