Showing posts with label next. Show all posts
Showing posts with label next. Show all posts

3/15/2023

get first item in dict (python sample code)

 refer to code:


.

my_dict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

# Get the first key-value pair from the dictionary
first_key, first_value = next(iter(my_dict.items()))

print("First key:", first_key)
print("First value:", first_value)

..


Thank you.

www.marearts.comπŸ™‡πŸ»‍♂️

9/23/2020

Pytorch, Infinite DataLoader using iter & next

 


# create dataloader-iterator
data_iter = iter(data_loader)

# iterate over dataset
# alternatively you could use while(True)
for i in range(NUM_ITERS_YOU_WANT)
try:
data = next(data_iter)
except StopIteration:
# StopIteration is thrown if dataset ends
# reinitialize data loader
data_iter = iter(data_loader)
data = next(data_iter)