まめたろう まめたろう - 1 month ago 9
Python Question

Code Golf easy One line for statement for one time skip

I wanna first time skip
but many count. im Stupid.

count = 0
for a in articles:
if count == 0:
count += 1
continue
data = a.b.c()
etc = a.abcde(E)
# ~~~~..........


completed code

for c,l in enumerate(BeautifulSoup(requests.get(NS_URL, timeout=3).text, 'lxml').find_all('li')):
if c == 0: continue
link = l.a.get('href')
title = l.h1.a.text
img = l.img.get('src')

Answer

If you want to iterate over the items and count them, use the enumerate() function:

for count, a in enumerate(articles):
    if count == 0:
        continue
    # now do whatever
Comments