Reverse Lists

+1 Landon Luman · August 19, 2014
So, I really want to know if there is an opposite to the list function for arrays. Because I want to be able to turn an input into a list, delete a few characters, then make it one big array again.

If there is a way, please tell me!

If there is an alternative way, I will except it too!


Post a Reply


Oldest  Newest  Rating
+1 Bucky Roberts · August 19, 2014
So you want to allow the user to type in a string, convert that string to a character array, and delete characters from the end?

Can you tell me what your program is trying to accomplish. I have a feeling that there is an easier way to do it. 
+1 name family · August 19, 2014
if your input is a string . it is a kind of list ;) 
0 Yoncho Yonchev · August 19, 2014
Something like that will do :

# this is written in python 3.4 , be aware of the diffrerence with python 2.7
def string_pos_removal(my_string,pos):
   '''Here is the tricky part when you have to be sure
   that pos is less then the length of the my_string'''

   return my_string[0:pos]+my_string[pos+1:]

my_string=input('Please enter your word dude :) Is it tuna  ?')
if pos <=len(my_string):
   print('Count more carefully mate !')

Edit: This code tags are not supporting PEP8, shame . The tabs look funny here.
0 James Nichols · August 21, 2014
If you use a list then you can just use list.reverse()
0 Yoncho Yonchev · August 25, 2014
@James Nichols , read the question first and for your information you dont need to convert string to list to reverse it :


  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator