Z
Z
zhabaa2021-11-17 20:42:09
Python
zhabaa, 2021-11-17 20:42:09

How can the code be made easier to understand?

I don't understand how list loops work.

w, n = [input() for i in range(int(input()))], int(input())
print(''.join((i[n - 1] for i in w if 1 <= n <= len(i))))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LXSTVAYNE, 2021-11-17
@zhabaa

Such complex nested constructs should never be used, they are very difficult to read. By the way, list comprehensions will not add any performance here. It's better to make the code more readable:

n = int(input())
w = []
count = int(input())
for _ in range(count):
    w.append(input())

for i in w:
    if 1 <= n <= len(i):
        print(i[n - 1], end='')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question