Python Lambda Function for List operations -
what missing here ? if list size greater 5, need last element, else first element.
fn = lambda *d: d[-1] if len(d) > 5 else d[0] print map(fn,[1,2,3,4,5,6,7,8,9,10]) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
this wanted, probably:
fn = lambda d: d[-1] if len(d) > 5 else d[0] print fn([1,2,3,4,5,6,7,8,9,10]) 10 print fn([1,2,3]) 1
Comments
Post a Comment