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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:48:12+00:00 2026-06-02T20:48:12+00:00

I have a list of items.. An orginal list and a modified list –

  • 0

I have a list of items.. An orginal list and a modified list – what i want to know is which elements have been removed/added from the modified list and what position w.r.t to the original list. The lists do not have duplicates and are not sorted because the ordering of the items in the list matters. Take an example

Org = ['AMEND', 'ASTRT', 'ETIME', 'OBJ', 'ast', 'bias', 'chip', 'cold']
mod = ['AMEND', 'ASTRT',         'OBJ', 'ast', 'bias', 'chip', 'cold', 'flat', 'deb']

in the mod_list ‘ETIME’, was removed and ‘flat’, deb’ were added – so the result of this would be ‘ETIME’ removed at index 2 and ‘flat’, deb’ added at index 8 & 9.

My other problem is detecting if items have changed position. In the example below ‘OBJ’, and ‘ASTRT’ have changed positions.

Org = ['AMEND', 'ASTRT', 'ETIME', 'OBJ', 'ast', 'bias', 'chip', 'cold']
mod = ['AMEND', 'OBJ', 'ETIME', 'ASTRT', 'ast', 'bias', 'chip', 'cold']

Any ideas on how to solve this!

  • 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-02T20:48:13+00:00Added an answer on June 2, 2026 at 8:48 pm

    You can use difflib to do this kind of thing:

    >>> import difflib
    >>> Org = ['AMEND', 'ASTRT', 'ETIME', 'OBJ', 'ast', 'bias', 'chip', 'cold']
    >>> mod = ['AMEND', 'ASTRT', 'OBJ', 'ast', 'bias', 'chip', 'cold', 'flat', 'deb']
    >>> list(difflib.ndiff(Org, mod))
    ['  AMEND', '  ASTRT', '- ETIME', '  OBJ', '  ast', '  bias', '  chip', '  cold', '+ flat', '+ deb']
    

    From here you can iterate through the list and check if items are new or moved or missing. For example:

    Org = ['a', 'b' ,'c', 'd', 'e', 'f', 'g', 'h', 'i']
    mod = ['i', 'b', 'c', 'z', 'd', 'f', 'g', 'h', 'a']
    differences = set(difflib.ndiff(Org, mod))
    
    moved = set([item[2:] for item in differences if item[0]=='+' and '-' + item[1:] in differences])
    removed = set([item[2:] for item in differences if item[0]=='-']) - moved
    added = set([item[2:] for item in differences if item[0]=='+']) - moved
    
    print 'moved items:', moved
    print 'removed items:', removed
    print 'added items:', added
    #output:
    moved items: set(['a', 'i'])
    removed items: set(['e'])
    added items: set(['z'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do this: I have a inline list which N elements. Elements
I have 5 list items, when one is clicked the only method I know
I have a list which is dynamically built, but there are empty list items
I have a list of items of type ViewLookupItem which has these properties: For
I have a list of items, which has two values, a name and an
Within my code I have list items like this; <div id=content> <ul class=kwicks> <li
Can someone suggest what I am doing wrong? Basically I have a List Items,
I have List with n items. I wish transform my list to new list,
I have a list of items, like a menu, where the current item has
I have a list of items (lets says 30 strings); I'm trying to figure

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.