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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:26:37+00:00 2026-05-30T05:26:37+00:00

What i have only removes duplicated items and sorts them. I need to remove

  • 0

What i have only removes duplicated items and sorts them. I need to remove one instance of every item and return a new list with the items in it. This is what i have:

def rem(nlst):
    n = []
    for x in nlst:
        if x not in n:
            n.append(x)
            n.sort()
    return n

This is what it should do:

>>> rem([4])
[]
>>> rem([4,4])
[4]
>>> rem([4, 1, 3, 2])
[]
>>> rem([2, 4, 2, 4, 4])
[2, 4, 4]
  • 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-05-30T05:26:38+00:00Added an answer on May 30, 2026 at 5:26 am

    An easy implementation is to use collections.Counter:

    def rem(iterable):
        c = collections.Counter(iterable)
        for k in c:
            c[k] -= 1
        return sorted(c.elements())
    

    In Python versions before 2.7, collections.Counter is not available. You can use a set to record the items you already saw instead:

    def rem(iterable):
       result = []
       seen = set()
       for x in iterable:
           if x in seen:
               result.append(x)
           else:
               seen.add(x)
       result.sort()
       return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have only one class with many instances. Every instance is observer of couple
RemoveDirectory() removes only empty directories. How do I remove directories that have files inside?
I want to remove only those ul with li that doesn't have a custom
I have a string which contains only numbers. Now I want to remove all
Python: How to remove all duplicate items from a list Hey guys I have
Possible Duplicate: Remove Duplicate Rows Leaving Oldest Row Only? I have a posts_table in
I have a rather specific question about how to exclude items of one list
Is there any possibility in SQL to remove (only one) duplicate entries of composed
Possible Duplicate: python .rstrip removes one additional character i have a string vtype defined
In Core Data is there a way to have one instance of an object

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.