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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:24:08+00:00 2026-06-08T10:24:08+00:00

I have a list of items that I need to bubble sort. The bubble

  • 0

I have a list of items that I need to bubble sort. The bubble sort criteria is if item j is ranked higher than item i in a majority of result sets, swap item j with item i in FullList. I have a very simple bubble sort figured out except for one small problem. I get a key error when the FullList item doesn’t appear in one of the result sets. I need to put in a value to compensate for that or else my loop becomes very complicated with numerous if statements. If I could assign a token value such as 20 to any value that doesn’t exist in the dictionary, my loop will be perfect. Can anyone help me out?

FullList = [B,C,A,D,H,E,F,G]

Results1 = {'A':1,'B':2,'C':3,'D':4,'E':5}
Results2 = {'B':1,'D':2,'G':3,'F':4,'E':5}
Results3 = {'C':1,'D':2,'B':3,'A':4,'H':5}

Pseudo Code:

switch = True
while(switch):
switch = False
    for i in range(len(FullList)-1):
        if FullList[i+1]<FullList[i] in Results1 & 2:
           FullList[i],FullList[i+1] = FullList[i+1],FullList[i]
           switch = True
        elif FullList[i+1]<FullList[i] in Results1 & 3:
             FullList[i],FullList[i+1] = FullList[i+1],FullList[i]
             switch = True
        elif FullList[i+1]<FullList[i] in Results2 & 3:
             FullList[i],FullList[i+1] = FullList[i+1],FullList[i]
             switch = True

Key-Error: 'A' not in 'Results2'    
  • 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-08T10:24:11+00:00Added an answer on June 8, 2026 at 10:24 am

    don’t know exactly what you are trying to do, but seems like get(key[, default]) is what you need, you can check out the details of this here

    In your case, Results2.get('A', 20) will give you 20

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

Sidebar

Related Questions

I have a list of items that I need to update on different intervals.
I have items in a list in a SharePoint 2003 site that I need
I have list of items that need to be processed and printed to the
I want to have a list of items that need to be processed in
I have a list of items that I need to record its position in
I'm displaying a long list of items that I need to sort with 3
I have 60k items that need to be checked against a 20k lookup list.
I have a list of work items that need to be processed in order.
I need to rearrange a list of items so that the selected item goes
I have a list of items that I need to re-sequence with no gaps.

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.