Python - Removing an element in list

How would i go about hiding the last element from a list. For example, Python outputs ['Go shopping @H']. Just wondering what code would I use to remove the @H from the result.

Answers


If you want to remove the last two characters, you can do this:

l[0]=l[0][:-2]

If you want to remove an element followed by @, you can do this:

import re
l[0]=re.sub("@[a-zA-Z]*",'',l[0])

If you print l after any of these operations, you'll get ['Go shopping '].

If you need to do the same for each element of the list, you can loop through it removing the thing you want to remove.

for x in xrange(0, len(your_list)-1):
    your_list[x]= # use one of the methods mentioned above

Need Your Help

Sending a simple string to PHP using javascript prompt

javascript php jquery sql

I have a simple function in my php file mean to collect emails and send them to a database.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.