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 8180399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:12:18+00:00 2026-06-07T00:12:18+00:00

I use python 2.7. I have data in file ‘a’: myname1@abc.com;description1 myname2@abc.org;description2 myname3@this_is_ok.ok;description3 myname5@qwe.in;description4

  • 0

I use python 2.7.
I have data in file ‘a’:

myname1@abc.com;description1
myname2@abc.org;description2
myname3@this_is_ok.ok;description3
myname5@qwe.in;description4
myname4@qwe.org;description5
abc@ok.ok;description7

I read this file like:

with open('a', 'r') as f:
    data = [x.strip() for x in f.readlines()]

i have a list named bad:

bad = ['abc', 'qwe'] # could be more than 20 elements

Now i’m trying to remove all lines with ‘abc’ and ‘qwe’ after @ and write the rest to the newfile.
So in newfile should be only 2 lines:

myname3@this_is_ok.ok;description3
abc@ok.ok;description7

I’ve been tryin to use regexp (.?)@(.?);(.*) to get groups, but i don’t know what to do next.

Advice me, please!

  • 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-07T00:12:19+00:00Added an answer on June 7, 2026 at 12:12 am
    import re
    bad = ['abc', 'qwe']
    
    with open('a') as f:
        print [line.strip() 
               for line in f
               if not re.search('|'.join(bad), line.partition('@')[2]]
    

    This solution works as long as bad only contains normal characters eg. letters, numbers, underscores but nothing that interferes with the regex expression like 'a|b' as @phihag pointed out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 python scripts https://gist.github.com/2233477 . rsgen.py generates random inputs for use in
I have external data input that I use in my python scripts (in fact
You have a Python class which needs an equals test. Python should use duck-typing
i have an issue i could use some help with, i have python list
I have a Python script that makes use of 'Print' for printing to stdout.
I have a Python Facebook project hosted on Google App Engine and use the
I am learning how to use sqlite3 in python. I have a simple table
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create
I have installed WMI for python and pywin32 extensions to be able to use
I have Django 1.4 and Python 2.6.6 When I use django-amdin.py startproject djproject follow

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.