I'm iterating over tweets using :
for status in tweepy.Cursor(api.user_timeline, screen_name='@realDonaldTrump').items():
But I want just the first 1000
items.
I can define an variable i=0
outside of the loop and then use if
and i=i+1
to check if I've iterated enough. But it doesn't feel "pythony...", more C style
I've hoped there is some trick to it, like:
for status, i in (tweepy.Cursor(api.user_timeline, screen_name='@realDonaldTrump').items(), np.arange(10)):
Which of course doesn't work
Thanks
Use islice
to do something similar to list[:10]
:
from itertools import islice
cursor = tweepy.Cursor(api.user_timeline, screen_name='@realDonaldTrump').items()
for status in islice(cursor, 10):
pass
To keep track of the index you can use the built-in enumerate
:
for i, status in enumerate(cursor):
pass
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I am working with datasets and dataframes (Python) and I want to express the ratio of the median of a certain set of values, by means of taking the absolute value of (mean-median)/median
I've been searching the web for quite a while and couldn't find an answer
what is the best way to put the button at the edge of sidenav?