4
Contributors
6
Replies
56
Views
3 Years
Discussion Span
Last Post by krystosan
0

Your question isn't very clear; can you provide a sample input/output for the use case in consideration?

0

Create a tuple of special characters you will be checking for. Create a for loop and use string.find()
Maybe you can implement it as follows:

test="How are you?!!!#"
#Say you have a list of chrs like @,#,$,!,%,^,&,* etc
spl_chr='!'#If you are looking for !
loc=test.find(spl_chr)
if loc==-1:
    print "not found"
else:
    print "Found spl caracter at "+loc

Thats all. For more special characters you can create an array of spl characters and check for each one in a loop

0

i did something like this

strng = '1002-1004,1 1444'

[each for each in strng.split("-")[-1] if each in [',',' ','*','"','#','-']

i don't rememeber how i did in workplace, but it was better ..

0

this was it
import re

[char for char in strng if re.search(r"[^a-wy-zA-WYZ0-9]",char)]

1

Shorter.

>>> strng = '1002-1004,1 1444'
>>> re.findall(r'\W', strng)
['-', ',', ' ']

Or the same without regex.

>>> strng = '1002-1004,1 1444'
>>> [c for c in strng if c in ['-', ',', ' ']]
['-', ',', ' ']
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.