It seems like there should be a simpler way than:
import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
Is there?
|
I've got a pretty good working snippit of code, but I was wondering if anyone has any better suggestions on how to do this:
val = ''.join([c for c in val if ...
|
url = 'abcdc.com'
print url.strip('.com')
Expect: abcdc
Resut: abcd
Now I do
url.rsplit('.com', 1)
Is there a better way..
|
Let's say I'm parsing a file, which uses ; as the comment character. I don't want to parse comments. So if I a line looks like this:
example.com. ...
|
I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python ... |
How do I strip comma from the end of a string? I tried
awk = subprocess.Popen([r"awk", "{print $10}"], stdin=subprocess.PIPE)
awk_stdin = awk.communicate(uptime_stdout)[0]
print awk_stdin
temp = awk_stdin
t = temp.strip(",")
also tried t = temp.rstrip(","), both ... |
ok I know that this should be simple... anyways say:
line = "$W5M5A,100527,142500,730301c44892fd1c,2,686.5 4,333.96,0,0,28.6,123,75,-0.4,1.4*49"
I want to strip out the spaces. I thought you would just do this
line = line.strip()
but now line ... |
|
>>> t1 = "abcd.org.gz"
>>> t1
'abcd.org.gz'
>>> t1.strip("g")
'abcd.org.gz'
>>> t1.strip("gz")
'abcd.org.'
>>> t1.strip(".gz")
'abcd.or'
Why does the 'g' of '.org' is gone?
|
I want to strip double quotes from
string = '"" " " ""\\1" " "" ""'
to become
string = '" " " ""\\1" " "" "'
I tried to use rstrip, lstrip and strip('[^\"]|[\"$]') ... |
good day guys! suppose i have a string with a format like so ^a.b.c^ and i want to only get a.b.c . can you teach me a more efficient way to ... |
I found this thread: Best way to strip punctuation from a string in Python
But was hoping to come up with a way to do this except not to strip out ... |
Here's the problem, I have a unicode string as input to a python sqlite query. The query failed ('like'). It turns out the string, 'FRANCE' doesn't have 6 characters, it has ... |
I have the following string:
text = 'adsfklaiin2007daf adf adflkajf;j 2008afadfkjkj'
I want to return:
2007 2008
Any way to do this in Python?
|
I got a string looking like that:
EVENTS: RAID
Volume Set Information
Volume Set Name : ARC-1120-VOL#00
Raid Set Name : Raid Set # 00
Volume Capacity : 1.0GB
SCSI ...
|
I want to strip out <p> and </p> from a string (lets say s).
Right now I am doing this :
s.strip('"<p>""</p>"')
I am not really sure if what I am doing is correct, ... |
I do not understand the end of this statement:
print node.getElementsByTagName(`author')[0].childNodes[0].data.strip()
What does data.strip() do in this statement?
|
Either this is a bug, or I'm about to learn something new about how Python behaves. :)
I have a dictionary filled with key/value pairs. Each key has a unique prefix, ias_XX_XX_. ... |
I know similar questions were asked around here on StackOverflow. I tryed to adapt some of the approaches but I couldn't get anything to work, that fits my needs:
Given a python ... |
I got a problem, it's about converting from List to String to edit it
I have file text content these name
Roby
Bucky
johan
Then I want to add beside each one OK:1
so i do this ... |
How can you use string methods like strip() on a unicode string? and can't you access characters of a unicode string like with oridnary strings? (ex: mystring[0:4] )
|
i'm trying to strip characters from timestamp stored in matrix (or list of lists if you want). i want to extract the item and use it as a filename after stripping ... |
Possible Duplicate:
python str.strip strange behavior
I have following piece of code:
st = '55000.0'
st = st.strip('.0')
print st
When i execute, it print only 55 but i expect ... |
I want to strip all characters after a third character, say - for instance.
I found this code online and it works but I'm having trouble learning how it works and wanted ... |
|
|
|
neddie wrote:True, but if the source doesn't start with the intro, the split will carry on looking through the whole string looking for the text. And if it does find the intro somewhere else, it will construct two new strings and put them into a new list. Then you have to check the first string whether it's empty or not, and ... |