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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:28:36+00:00 2026-05-22T19:28:36+00:00

I have a list that I’m attempting to remove duplicate items from. I’m using

  • 0

I have a list that I’m attempting to remove duplicate items from. I’m using python 2.7.1 so I can simply use the set() function. However, this reorders my list. Which for my particular case is unacceptable.

Below is a function I wrote; which does this. However I’m wondering if there’s a better/faster way. Also any comments on it would be appreciated.

    def ordered_set(list_):

        newlist = []
        lastitem = None
        for item in list_:

            if item != lastitem:
                newlist.append(item)
                lastitem = item

        return newlist

The above function assumes that none of the items will be None, and that the items are in order (ie, [‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘c’, ‘d’])

The above function returns [‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘c’, ‘d’] as [‘a’, ‘b’, ‘c’, ‘d’].

  • 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-22T19:28:37+00:00Added an answer on May 22, 2026 at 7:28 pm

    Use an OrderedDict:

    from collections import OrderedDict
    
    l = ['a', 'a', 'a', 'b', 'b', 'c', 'd']
    d = OrderedDict()
    
    for x in l:
        d[x] = True
    
    # prints a b c d
    for x in d:
        print x,
    print
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list items in an unordered list that when double clicked, can be
I have a List that contains items, for example: 1) https:\\10.12.23\\ 2) https:\\12.23.12.25\\ 3)
I have a specialized list that holds items of type IThing : public class
I have list items that displayed inline. I want to align them vertically inside
I have a list that is pulled from three tables, Department, Type and User.
i have list of items IList with data that looks list this: GenId TestMode
I have this list that can be sorted with sortable. How can I move
I have a list that I need to fill using a JSON collection of
I have a list that the user can filter in several ways. two of
I have one list (list a) that increases based on size and has items

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.