473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

stripping parts of elements in a list

folks,
I am new to python.

I have a list made of elements

['amjad\n', 'kiki\n', 'jijiji\n']
I am trying to get rid of '\n' after each name.
to get list as
['amjad','kiki','jijiji']

But list does not have a strip function as string does have.

is there any solutions

Is there a way this can be done??

Oct 28 '06 #1
2 1342
"CSUIDL PROGRAMMEr" <sy*********@yahoo.comwrites:
['amjad\n', 'kiki\n', 'jijiji\n']
I am trying to get rid of '\n' after each name.
to get list as
['amjad','kiki','jijiji']

But list does not have a strip function as string does have.

is there any solutions
a = ['amjad\n', 'kiki\n', 'jijiji\n']

b = [x.strip() for x in a]

print b
Oct 28 '06 #2
CSUIDL PROGRAMMEr wrote:
folks,
I am new to python.

I have a list made of elements

['amjad\n', 'kiki\n', 'jijiji\n']
I am trying to get rid of '\n' after each name.
to get list as
['amjad','kiki','jijiji']

But list does not have a strip function as string does have.
What would a list.strip() method mean on a list of integers ?
is there any solutions
mylist = ['amjad\n', 'kiki\n', 'jijiji\n']
print "with map : "
print map(str.lstrip, mylist)
print "with list comprehension :"
print [line.lstrip() for line in mylist]
print "with a for loop :"
strippedlist = []
for line in mylist:
strippedlist.append(line.lstrip())
print strippedlist
Is there a way this can be done??
Probably. Reading some CS101 tutorial might be a good idea...

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Martin | last post by:
I have a HTML parser that reads product pages from various retailers - and I want to optimize it somewhat: I download all HTML before I start the parsing - and to do that I want to: - Get rid...
1
by: Andy Jefferies | last post by:
I'm having problems stripping out the whitespace at the beginning of a particular element. In the XML snippet I've highlighted tabs and returns as ^I and ^M respectively: <para> ^I ^I ...
2
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I...
8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
1
by: Foxpointe | last post by:
Given some arbitrary XHTML, I'd like to obtain a 'simplified' XHTML result which strips out a large subset of standard elements and attributes - but not all. The main things I would like to...
3
by: Rick | last post by:
I have a customer order form with a subform that lists parts per customer order that I'm updating. I'm trying to filer the parts list per Manufacture and Model number so that the user doesn't have...
3
by: Michel Bouwmans | last post by:
Hey everyone, I'm trying to strip all script-blocks from a HTML-file using regex. I tried the following in Python: testfile = open('testfile') testhtml = testfile.read() regex =...
4
by: Tim Cook | last post by:
Hi All, I just ran into an issue with the rstrip method when using it on path strings. When executing a function I have a need to strip off a portion of the current working directory and add...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.