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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:15:34+00:00 2026-06-16T00:15:34+00:00

Background: I have a Hash that I am iterating through to print it in

  • 0

Background: I have a Hash that I am iterating through to print it in a nice format.

Sample Hash

Final = {
    'sf_market_flash_subscribers': [
        {'38': './BLMetricsSql.sql'}
    ], 
    'vw_owner_product_bls_only': [
        {'31': './BLMetricsSql.sql'}, 
        {'39': './BLMetricsSql.sql'}, 
        {'62': './BLMetricsSql.sql'}, 
        {'64': './BLMetricsSql.sql'}
    ]
}

My Code

def printFinal(final):
    for key, value in final.iteritems():
        print key
        print value
        line_num=""
        path=""
        uniqueTables=[]
        for line_and_path in value:
            path=line_and_path.values()[0]
            uniqueTables.append(path)
            print uniqueTables
    print uniqueTables
    uniqueTables=list(set(uniqueTables))
    print uniqueTables
    for unique_path in uniqueTables:
        print unique_path
        for line_and_path in value:
            if line_and_path.values()[0]==unique_path.rstrip():
                line_num = line_and_path.keys()[0]
                print line_num

Output of the above code

sf_market_flash_subscribers
[{'38': './BLMetricsSql.sql'}]
['./BLMetricsSql.sql']
vw_owner_product_bls_only
[{'31': './BLMetricsSql.sql'}, {'39': './BLMetricsSql.sql'}, {'62': './BLMetricsSql.sql'}, {'64': './BLMetricsSql.sql'}]
['./BLMetricsSql.sql']
['./BLMetricsSql.sql', './BLMetricsSql.sql']
['./BLMetricsSql.sql', './BLMetricsSql.sql', './BLMetricsSql.sql']
['./BLMetricsSql.sql', './BLMetricsSql.sql', './BLMetricsSql.sql', './BLMetricsSql.sql']
['./BLMetricsSql.sql', './BLMetricsSql.sql', './BLMetricsSql.sql', './BLMetricsSql.sql']
['./BLMetricsSql.sql']
./BLMetricsSql.sql
31
39
62    
64

Look at the first 4 lines of output

The loop prints the key and value in line 1 and 2 respectively
Then it prints the current state of the unique table inside the loop
After that, BOOM all the remaining code does not get executed and it goes and loops over the second element in the final hash vw_owner_product_bls_only and then starts executing it. However, for this element all the code after the inner loop gets executed and I get the desired output.

So, why is the rest of the code not running only for the first element in the final hash? Is it because the value in the hash only has one element?

  • 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-16T00:15:35+00:00Added an answer on June 16, 2026 at 12:15 am

    You initialise uniqueTables every time round the loop, so the code outside the loop only sees the most recent value, which is the second element. The initialisation needs to be at the outermost level:

    def printFinal(final):
        uniqueTables = []
        for key, value in final.iteritems():
            # etc
        print uniqueTables
        uniqueTables=list(set(uniqueTables))
        # etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a function that takes a config object as an argument. Within
Background: I have a WebPart that makes use of the SPCalendarView control and in
Background I have a dimension table that has a single record for each day.
I have a default css sheet that uses an image for the background but
BACKGROUND I have a multidimensional hash which I want to perform a check to
Does MATLAB have any support for hash tables? Some background I am working on
Background: I have am taking over an application (original engineer is leaving) that act
Background: I have an MVC based polaroid object. The model keeps the photo's metadata,
Background I have an array of objects (Users) defined and set as follows: //
Background I have two lists, the first is items which contains around 250 tuples,

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.