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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:53:42+00:00 2026-06-10T06:53:42+00:00

Say I create a dictionary like so: self.defaultValues = {} self.defaultValues[A] = 10 self.defaultValues[B]

  • 0

Say I create a dictionary like so:

self.defaultValues = {}
self.defaultValues["A"] = "10"
self.defaultValues["B"] = "100"
self.defaultValues["C"] = "20"
self.defaultValues["D"] = "12.5"

I want to be able to iterate the items in the same order I added them, meaning

for k in self.defaultValues:
     print k

would result in

A
B
C
D

Also, if I have another list, not necessarily of the same length. I want to iterate both the dictionary and the list, and if a value exist in the list I will print it, otherwise I will print if form the dictionary. Its easy to do with a simple

if self.list.count(value) != 0:

But I think there might be a more elegant way to do it.

Thanks!

  • 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-10T06:53:43+00:00Added an answer on June 10, 2026 at 6:53 am

    For the first problem, use an OrderedDict:

    from collections import OrderedDict
    d = OrderedDict()
    d["A"] = "10"
    d["B"] = "100"
    d["C"] = "20"
    d["D"] = "12.5"
    for k in d:
        print k
    

    OrderedDict respects the order in which elements were inserted.

    For your second question (you should really make separate questions for separate problems), you can use in to test if an object is in the list:

    l = [1,2,3,4]
    print 1 in l # prints True
    print 5 in l # prints False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you create a directory like: CREATE OR REPLACE DIRECTORY EXT_DATA_FILES AS '/data/ext_data_files'; GRANT
Say I create some object class like so public class thing { private String
Let's say I create an instance of a class and want to assign some
Let's say I create a jagged 2d array like so: public static char[,] phoneLetterMapping
How do I create a nested dictionary in python So, I want the data
I have a table of dictionary terms and now I would like to create
Say I create one object and add it to my ArrayList . If I
Let's say I create a new Entity and Save it as follows: UserReport report
Just starting to study the Azure framework. Just say you create a row in
Let's say that I create a vector/array in Scheme: (let* ((x #(1 2 3)))

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.