I'm looking for an equivalent in python of dictionary.get(key, default)
for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available?
For example, given a list myList I would like to get myList[0]
, or 5 ifmyList
is an empty list.
Thanks.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…