[Solved] ‘str’ object has no attribute ‘pop’ [duplicate]


a is assigned a string returned by input(), so you need to turn it into a list first before you can use list methods such as pop() on it.

For example, by using a.split() you can treat a as a space-delimited string:

a = input('enter a list : ')
n = a.split()
p = 2
i = 0
l = len(n)
while l>0:
    i = (p+i)%l
    print(n.pop(i))
    l -= 1

Sample input and output:

enter a list : 3 5 2 1
2
5
1
3

0

solved ‘str’ object has no attribute ‘pop’ [duplicate]