Re: [Tutor] Removing control characters

2009-02-19 Thread Mark Tolonen
"Kent Johnson" wrote in message news:1c2a2c590902191500y71600feerff0b73a88fb49...@mail.gmail.com... On Thu, Feb 19, 2009 at 5:41 PM, Dinesh B Vadhia wrote: Okay, here is a combination of Mark's suggestions and yours: # replace unwanted chars in string s with " " t = "".join([(" " if n in

Re: [Tutor] Removing control characters

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 5:41 PM, Dinesh B Vadhia wrote: > Okay, here is a combination of Mark's suggestions and yours: >> # replace unwanted chars in string s with " " >> t = "".join([(" " if n in c else n) for n in s if n not in c]) >> t > 'Product ConceptsHard candy with an innovative twist, In

Re: [Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
;Product ConceptsHard candy with an innovative twist, Internet Archive: Wayback Machine. [online] Mar. 25, 2004. Retrieved from the Internet http://www.confectionery-innovations.com>.' This last bit doesn't work ie. replacing the unwanted chars with " " - eg. 'ConceptsHar

Re: [Tutor] Removing control characters

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 2:25 PM, Dinesh B Vadhia wrote: > # 3) Replacing a set of characters with a single character ie. > > for c in str: > if c in set: > string.replace (c, r) > > to give > >> 'Chris Perkins : $$$-' > My solution is: > > print ''.join[string.replace(c, r) for c

Re: [Tutor] Removing control characters

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 11:25 AM, Dinesh B Vadhia wrote: > My solution is: > > print ''.join[string.replace(c, r) for c in str if c in set] > > But, this returns a syntax error. Any idea why? > Probably because you didn't use parentheses - join() is a function. -- www.fsrtechnologies.com

Re: [Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
r: if c in set: string.replace (c, r) to give > 'Chris Perkins : $$$-' My solution is: print ''.join[string.replace(c, r) for c in str if c in set] But, this returns a syntax error. Any idea why? Ta! Dinesh From: Kent Johnson Sent: Thursday, Februar

Re: [Tutor] Removing control characters

2009-02-19 Thread Mark Tolonen
A regex isn't always the best solution: >>> a=''.join(chr(n) for n in range(256)) >>> a '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmno

Re: [Tutor] Removing control characters

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 10:14 AM, Dinesh B Vadhia wrote: > I want a regex to remove control characters (< chr(32) and > chr(126)) from > strings ie. > > line = re.sub(r"[^a-z0-9-';.]", " ", line) # replace all chars NOT A-Z, > a-z, 0-9, [-';.] with " " > > 1. What is the best way to include all