Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:36:00+00:00 2026-06-09T04:36:00+00:00

I am trying to solve a problem to remove HTML tags from a string.

  • 0

I am trying to solve a problem to remove HTML tags from a string. I realize that regular expressions are a better solution, but I’d like to figure out what is going wrong here.

The idea is to assume that we monitor being in a tag using ‘tag’, with it’s value being modified by comparing the value of each char.

The problem is, the value of tag is never changed:

def remove_tag(s):
    tag = True

    for c in s:
        print "c = %s" % c
        if (c == '<'):
            print 'start_tag'
            tag == True
            print tag
        elif (c == '>'):
            print 'end tag'
            tag == False
            print tag

Running:

remove_tag("<h1>Title</h1>")

Produces:

c = <
start_tag
True
c = h
c = 1
c = >
end tag
True
c = T
c = i
c = t
c = l
c = e
c = <
start_tag
True
c = /
c = h
c = 1
c = >
end tag
True
None

I am baffled as to why ‘end tag’ is printed but the value ‘False’ does not get assigned to tag.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:36:01+00:00Added an answer on June 9, 2026 at 4:36 am

    These lines are comparisons, not assignments:

    tag == True
    tag == False
    

    You want

    tag = True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names):
I'm trying to solve the problem here but I don't know why my code
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
I'm trying to filter out some garbage text from a string with regex but
I've been trying to solve this problem for quite sometime but I am having
I am trying to remove / replace white space from a string in as3.
i'm trying to extract from proper noun from a tagged file. But the problem
So I'm trying to solve this problem that asks to look for palindromes in
The problem I am trying to solve involves comparing range values that are strings
I'm trying to solve Problem 13 of project euler, which involves the sum of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.