Error in a "List Reversing" python program -
everyone! beginner in python programming. writing python programme reverse given input list. next code it:
l1=list(input("enter numbers of list reversed : ")) l2=[] def rever(la,lb): if len(lb)==0: homecoming la else: homecoming rever(la.append(lb.pop(0)),lb) print rever(l2,l1)
for example, if input,
1,2,3
the output should be,
[3,2,1]
but not happening. python giving next error:
traceback (most recent phone call last): file "q3.py", line 10, in <module> print rever(l2,l1) file "q3.py", line 8, in rever homecoming rever(la.append(lb.pop(0)),lb) file "q3.py", line 8, in rever homecoming rever(la.append(lb.pop(0)),lb) attributeerror: 'nonetype' object has no attribute 'append'
i don't it. please help me out!!
may should @ this, instead of pop , append
in [5]: l1=list(input("enter numbers of list reversed : ")) come in numbers of list reversed : 1,2,3,4,5 in [6]: l1 out[6]: [1, 2, 3, 4, 5] in [7]: l2 = l1[::-1] in [8]: l2 out[8]: [5, 4, 3, 2, 1]
python list
No comments:
Post a Comment