Print first N items of a list/generator
This works for plain lists. It prints the first 3 items of the list
l=[1, 2, 3, 4]
print(l[:min(3, len(l))])
I want this work for lists with less then three items, too. If there is only one item in the list, then print one item.
AFAIK len(l) only works for lists. How to implement this for generators?