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

The Archive Base Latest Questions

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

I am trying to learn python, especially lists, and I have a small problem.

  • 0

I am trying to learn python, especially lists, and I have a small problem. I have two lists:

alist=[1,2,3,4,5,6,7,8,9,1,2,3]
blist=["a","b","c","d","e","f","g","h","i","a","b","c"]

what I’s like to do is remove duplicates from “both the lists”. i.e only when an element of alist and its corresponding element in blist (in pairs) are the same, I delete them. I am expecting an outcome, looking like:

alist=[1,2,3,4,5,6,7,8,9]
blist=["a","b","c","d","e","f","g","h","i"]

So, I try to first do a set on the zip:

kk=set(zip(alist,blist))

and then do:

alist[:],blist[:]=zip(*kk)

then I get:

alist=[5, 6, 4, 7, 3, 8, 2, 1, 9]
blist=['e', 'f', 'd', 'g', 'c', 'h', 'b', 'a', 'i']

as you can see, the order is not maintained. I was wondering if it was possible somehow to use “sorted” and “index” to get the lists in correct order. Any guidance would be much appreciated.

The python version is 2.7.3

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

    You could use collections.OrderedDict for this:

    In [16]: d = collections.OrderedDict.fromkeys(zip(alist, blist))
    
    In [17]: [k[0] for k in d]
    Out[17]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
    
    In [18]: [k[1] for k in d]
    Out[18]: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
    

    An ordered set — if it were available — would perhaps lead to an even cleaner solution.

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

Sidebar

Related Questions

I'm trying to learn python but have some problem running source files from power
Hi im trying to learn Python and have a err i can understand ,
I have been trying to learn python over the last couple of months and
I am trying to learn how Python reloads modules, but have hit a roadblock.
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
Trying to learn Regex in Python to find words that have consecutive vowel-consonant or
I'm trying to learn python and I'm having trouble importing a module. I have
I am trying to learn Django (and Python) and have created my own app
I am trying to learn OO Python, and I have a doubt regarding the
I'm trying to learn programming through Python and I like to know if it's

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.