How to implement function like this?
Paul Rubin
http
Tue Oct 23 05:45:57 EDT 2007
"Yinghe Chen" <yinghe.chen at jeppesen.com.rm> writes:
> def funcA(tarray):
> a = [2,3,4]
> if len(tarray) >=3:
> return a[0],a[1], a[2]
> elif len(tarray) == 2:
> return a[0],a[1], funcB(1)[0]
> elif len(tarray) == 1:
> return a[0], funcB(2)[0], funcB(2)[1]
> else:
> return funcB(3)[0], funcB(3)[1], funcB(3)[2]
untested:
from itertools import chain, islice
def funcA(tarray):
xB = max(3 - len(tarray), 0)
return chain(a, islice(funcB(xB), xB))
More information about the Python-list
mailing list