| Server IP : 121.121.20.254 / Your IP : 216.73.217.64 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Python315/Lib/test/__pycache__/ |
Upload File : |
R
>lqjg c � � ] PH s ] PHs] PHs] PHs] PHs] QHGs Qs Q Q\O 2 s Q\-s
Q s\Q6X c \O 2 P! P! )� )�
BrokenItera�
########### Tests borrowed from or inspired by test_genexps.py ############
Test simple loop with conditional
>>> sum([i*i for i in range(100) if i&1 == 1])
166650
Test simple nesting
>>> [(i,j) for i in range(3) for j in range(4)]
[(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3)]
Test nesting with the inner expression dependent on the outer
>>> [(i,j) for i in range(4) for j in range(i)]
[(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]
Test the idiom for temporary variable assignment in comprehensions.
>>> [j*j for i in range(4) for j in [i+1]]
[1, 4, 9, 16]
>>> [j*k for i in range(4) for j in [i+1] for k in [j+1]]
[2, 6, 12, 20]
>>> [j*k for i in range(4) for j, k in [(i+1, i+2)]]
[2, 6, 12, 20]
Not assignment
>>> [i*i for i in [*range(4)]]
[0, 1, 4, 9]
>>> [i*i for i in (*range(4),)]
[0, 1, 4, 9]
Make sure the induction variable is not exposed
>>> i = 20
>>> sum([i*i for i in range(100)])
328350
>>> i
20
Verify that syntax error's are raised for listcomps used as lvalues
>>> [y for y in (1,2)] = 10 # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
SyntaxError: ...
>>> [y for y in (1,2)] += 10 # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
SyntaxError: ...
########### Tests borrowed from or inspired by test_generators.py ############
Make a nested list comprehension that acts like range()
>>> def frange(n):
... return [i for i in range(n)]
>>> frange(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Same again, only as a lambda expression instead of a function definition
>>> lrange = lambda n: [i for i in range(n)]
>>> lrange(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Generators can call other generators:
>>> def grange(n):
... for x in [i for i in range(n)]:
... yield x
>>> list(grange(5))
[0, 1, 2, 3, 4]
Make sure that None is a valid return value
>>> [None for i in range(10)]
[None, None, None, None, None, None, None, None, None, None]
c �� ` `� \ sQ s]bs nPPPQD\1Q ksQ sQ sQ sU 1Q ks Q s
Q sQ sQ s
Q
sQ sQ sQ
sQ sQ sQ sQ sQ sQ sQ sQ sQ sQ sQ sQ sQ sQ sQ s Q s!Q s"Q s#Q s$Q! s%Q" s&Q# s'Q$ s(Q% s)Q& s*Q' s+Q( s,Q) s-Q* s.Q+ s/Q, s0Q- s1Q. s2Q/ s3Q0 s4Q1 s5Q2 s6Q3 s7Q4 s8Q5 s9Q6 s:Q7 s;Q8 s<Q9 s=Q: s>Q; s?Q< s@Q= sAQ> sBQ? sCQ@ sDQA sEQB sFQC sGQDsHUsIU 9sJ! )E�ListComprehensionTestc � � [ O U2 oS9% f , QNoSF CD oU O UQ5 9^tt^ 2 UQ6X c@ [ O Q2 O [ O UQ2 Q5 oQ o LKUQ6X c@ [ O Q2 O [ O UQ2 Q5 oQ o LSoQ
o U% c UO 2 L- o
U V�2 S9% f - O
2 F D v q�U O U V�2 V�2 J PPP2 CJ P! S c&