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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:42:29+00:00 2026-06-13T03:42:29+00:00

I am trying to do three simple steps efficiently in Python. I have a

  • 0

I am trying to do three simple steps efficiently in Python.

I have a list of lists (of strings). Let us call it L.

  1. I want to flatten the list of lists to a single list LL. (I know how to do this efficiently)

  2. Construct the set of words with frequency 1 from the list LL of step 1. Let us call this set S. (I also know how to do this
    efficiently)

  3. Remove all the words from the list of lists L which occur in S.

If you can suggest an efficient way of doing step 3, that will be a great help.

  • 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-13T03:42:31+00:00Added an answer on June 13, 2026 at 3:42 am

    use a simple list comprehension for the 3rd step:

    >>> from collections import Counter
    >>> from itertools import chain
    >>> L=[['a','b'],['foo','bar'],['spam','eggs'],['b','c'],['spam','bar']]
    >>> S=Counter(chain(*L))
    >>> S
    Counter({'b': 2, 'bar': 2, 'spam': 2, 'a': 1, 'c': 1, 'eggs': 1, 'foo': 1})
    
    >>> [[y for y in x if S[y]!=1] for x in L]
    [['b'], ['bar'], ['spam'], ['b'], ['spam', 'bar']]
    

    if you’ve a set R:

    >>> L=[['a','b'],['foo','bar'],['spam','eggs'],['b','c'],['spam','bar']]
    >>> R={'a','foo'}
    >>> [[y for y in x if y not in R] for x in L]
    [['b'], ['bar'], ['spam', 'eggs'], ['b', 'c'], ['spam', 'bar']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to keep my HTML very simple. I have a set list which
I have am trying to create a simple voting page. There are a few
I am trying to select three values from xml document. I want to get
I am trying to display three forms in one template. I have the forms
Trying to run a simple svn list svn+ssh://... from within jenkins on os X,
I'm trying to learn how to make a simple call to the server from
I'm trying to write a simple python extension for GDB that outputs to a
Hi there i am trying to do simple thing and cant manage to work
hi there i'm trying to make a simple parser and using lex and yacc.
I am trying to set up a simple css transition where there is a

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.