A
A
Amalat2021-10-07 12:21:10
Python
Amalat, 2021-10-07 12:21:10

Can you verbally explain a line of python code to me?

Issue resolved, thanks
to update.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-07
@Amalat

x = [
    "".join( #6
        [
            "".join( #3
                [
                    "01"[(i + j) % 2] * k #1
                    for i in range(n) #2
                ]
            ) + "\n" #4
        ] * k #5
    ) 
    for j in range(n) #7
]

1. If i + j is even, then generate a string of k zeros, otherwise, of k ones
2. Generate a list of n such strings, with index i
3. Glue the resulting strings without a separator
4. Glue a newline to the end.
5. We make a list of k repetitions of the string generated in step 4.
6. We glue these repetitions without a separator
7. We generate strings according to paragraphs. 1-6 n times with index j and form a list of them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question