python – Stripping Quotations from a List of Lists

I just always seem to mess up comprehensions when they have the = sign in them like this.

I found the best way to think about comprehensions is instead think of comprehensions as .appends.

Lets change your inner loop to use .append instead.
We don’t need to use enumerate as we’ll be building a new list.

def quote_strip(input_file):
    for k1, v1 in enumerate(input_file):
        inner_list = ()
        for v2 in v1:
            inner_list.append(v2.lstrip('"').rstrip('"'))
        input_file(k1) = inner_list
    return input_file

We can now change the code to a comprehension.
I’ll show you a pattern which we can just copy:

my_list = ()
for item in other_list:
    my_list.append(item + 1)

becomes:

my_list = (
    item + 1
    for item in other_list
)

We just move whatever is in the append(...) to the top of the comprehension.
And move the for loop into the bottom of the list.

def quote_strip(input_file):
    for k1, v1 in enumerate(input_file):
        inner_list = (
            v2.lstrip('"').rstrip('"')
            for v2 in v1
        )
        input_file(k1) = inner_list
    return input_file

You should notice we can remove the need for assigning to the name inner_list.

def quote_strip(input_file):
    for k1, v1 in enumerate(input_file):
        input_file(k1) = (
            v2.lstrip('"').rstrip('"')
            for v2 in v1
        )
    return input_file

Now we can change the loop to use .append again.

def quote_strip(input_file):
    output_list = ()
    for v1 in input_file:
        output_list.append((
            v2.lstrip('"').rstrip('"')
            for v2 in v1
        ))
    return output_list

And again we can change the code to a list comprehension.

def quote_strip(input_file):
    return (
        (
            v2.lstrip('"').rstrip('"')
            for v2 in v1
        )
        for v1 in input_file
    )

Extra

I am pretty sure there is a way of making this a single line

We can put the comprehension on one line but please do not do so.
How many lines of code you write is not important, how easy to read your code is.
Putting the comprehension on one line will make your code harder to read.