Handle iterable and non-iterable seamlessly
Posted
by Cheolho
on Stack Overflow
See other posts from Stack Overflow
or by Cheolho
Published on 2010-05-13T05:36:08Z
Indexed on
2010/05/13
5:44 UTC
Read the original article
Hit count: 264
Could you let me know how I can optimize the following code?
def f(y, list_or_elem):
if getattr(list_or_elem, '__iter__'):
y = max(y, *list_or_elem)
else:
y = max(y, list_or_elem)
© Stack Overflow or respective owner