Python superposition for statement

Asked 2 years ago, Updated 2 years ago, 83 views

If you write the code like above, the first variable tag is repeated, and then the second variable tags are added Can't you repeat both at the same time?

I want to repeat both in this form! I don't know if the explanation went well<

python crawling for

2022-09-21 22:14

1 Answers

The zip function allows you to bind the collection as shown below.

Note that each collection must have the same number. Otherwise, it will be cut off except for the pair being matched.

In [1]: for a, b in zip(range(10), range(10)): 
   ...:     ...:     print(a, b) 
   ...:                                                                         
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9

Try it as below.

for a, b in zip(soup.select('font > stong'), soup.select('lmis')):
    print(a, b)


2022-09-21 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.