I've written so many answers because I personally have used all these at different places in my mini-projects and projects. Some may be irrelevant according to question, but will be useful elsewhere.
list1 = list(range(100))
import tqdm
for x in tqdm.tqdm(list1):
sleep(0.01)
Or
tlist1 = tqdm.tqdm(list1)
for x in tlist1:
sleep(0.01)
Basically, you are passing the list to create a tqdm instance.
You can use another workaround as in tqdm documentation:
# DOESN't work well in terminal, but should be ok in Jupyter Notebook
with tqdm.tqdm(total=len(list1)) as t:
for x in list1:
sleep(0.01)
t.update(1)
Using generators with manual update of trange object:
def literate(list1):
t = trange(len(list1))
for x in list1:
t.update(1)
yield x
for x in literate(list1):
sleep(0.01)
With automatic update:
def li_iterate(li):
l = iter(li)
for _ in trange(len(li)):
yield next(l)
for x in li_iterate(list1):
sleep(0.01)
Apart from the question, if you are using pandas dataframe, you may want to use this sometime (in google-colaboratory):
# %% implies cell magic in google-colab
%%capture
from tqdm.notebook import tqdm as tq
tq().pandas()
def fn(x):
for a in list2:
print(x, a)
import pandas as pd
list1 = list(range(0, 9))
pd.DataFrame(data=list1).progress_apply(fn)
-Himanshu