using
while
.pop()
insert()
pop() the first item in the list and add to the beginning of a new string that will be reversed
# [ ] Challenge: write the code for "reverse a string" reversing some_numbers
some_numbers =[1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77]
rev_string = []
while len(some_numbers):
rev = some_numbers.pop()
rev_string.insert(0,rev)
print(rev)
print(some_numbers)
print(rev_string)
My first question is that:
- As i am printing rev in line 7, i am getting 1 as the answer but we know that an empty pop is used to denote the last element then why i am getting 1 instead of 77.
- I am getting the right answer by putting 0 inside the pop in line 5. How ?