0

I have this code, and i'm wondering why it doesn't work.

Tried:

event_date = re.findall(pattern,area)
for i in event_date:
    i.replace("<br>", " ")
    print i

and

event_date = re.findall(pattern,area)
for i in event_date:
    i.replace('<br>', ' ')
    print i

and

y = "<br>"
event_date = re.findall(pattern,area)
for i in event_date:
    event_date.index(y) and then using del... 

and rstrip, translate, and re.sub ...

print event_date returns every entry like this

Tue, 10/28/14<br>05:30 PM
...

I want to remove the br tag and replace it with an empty space, but nothing seems to work. Advice?

  • possible duplicate of [Find and replace string values in Python list](http://stackoverflow.com/questions/3136689/find-and-replace-string-values-in-python-list) – hwnd Jun 01 '14 at 01:29
  • Functionally the same, but the key learning here was that the replace function has no side-effects. – metaperture Jun 01 '14 at 01:35

2 Answers2

-1

The replace function doesn't modify the original. Try:

replaced = [i.replace("<br>",' ') for i in event_date]
print replaced
metaperture
  • 2,393
  • 1
  • 18
  • 19
  • [PEP-8](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCIQFjAA&url=https%3A%2F%2Fwww.python.org%2Fdev%2Fpeps%2Fpep-0008&ei=w3-KU8mrHoztoATc7YHYDQ&usg=AFQjCNGUTp-Bavhz439Hr22L2HoxWDeNGg&sig2=PnlX0ubBE_h1F-WURKd6ag&bvm=bv.68191837,d.cGU)? – A.J. Uppal Jun 01 '14 at 01:20
  • Thank you! It worked! I would + rep to you if I could! – user3626258 Jun 01 '14 at 01:20
  • @metaperture no need to rage and down vote my answer just because you thin I down voted yours, because I didn't. – A.J. Uppal Jun 01 '14 at 01:47
-1

Use a simple list comprehension instead, because i.replace() doesn't modify i:

event_date = re.findall(pattern,area)
event_date = [i.replace("<br>", " ") for i in event_date]
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76