Please explain to me what this Python code means?

I'm still learning python, but this code seems to be above my level. what does it mean?

 pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
+5
source share
1 answer

You can convert any list comprehension into an equivalent explicit loop as follows:

pairs = []
for s1 in qs.split('&'):
    for s2 in s1.split(';'):
        pairs.append(s2)

The rule is to take all the offers forand ifenclose them in the order in which they appear, and then append(foo)for any foountil the first sentence.

List Consrehension ( " " ), , ( ) , .

, urllib.parse.parse_qsl ( urlparse.parse_qsl 2.x) . , , (, ), , , , .

+11

All Articles