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

  • Home
  • SEARCH
  • 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 8090261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:39:49+00:00 2026-06-05T19:39:49+00:00

I am working on a program to delete blank values from lists inside dictionaries,

  • 0

I am working on a program to delete blank values from lists inside dictionaries, however if the entire value consists of a single array that holds only a single space, I need to delete the element containing the single space.

def CleanWhiteSpace(theDict) :
    stuff=[]
    for key2 in theDict.keys():
        for value2 in theDict.values(): 
            if value2 == [' ']:
                print key2
                del theDict[key2]
                print "hi"

    print theDict
    for key,value in theDict.iteritems():
        for d in value:
            print value
            if d != ' ':
                    stuff.append(d)    
            theDict[key]=stuff
        stuff=[]

    return theDict
print CleanWhiteSpace({'a':['1','2'],'b':['3',' '],'c':[' ']})

I only want this to delete key c.

  • 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-05T19:39:50+00:00Added an answer on June 5, 2026 at 7:39 pm

    For each key, you should only look at a single value, rather than looping over theDict.values().

    def CleanWhiteSpace(theDict) :
        stuff=[]
        for key2 in theDict.keys():  # this is the line I changed
            if theDict[key2] == [' ']:
                print key2
                del theDict[key2]
                print "hi"
    
        print theDict
        for key, value in theDict.iteritems():
            for d in value:
                print value
                if d != ' ':
                        stuff.append(d)
                theDict[key]=stuff
            stuff=[]
    
        return theDict
    print CleanWhiteSpace({'a':['1','2'],'b':['3',' '],'c':[' ']})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program to delete files from a certain folder after they
I'm working on a program that will need to delete a folder (and then
is there any small working program for recieving from and sending data to client
I have a working C program where the length of an array of strings
the program on which I am working gets data from a web service, adds
I am working on a program in which information from a form is reprinted
I'm working on a program, that needs to load data from a text file
I'm working on a program using doubly linked lists. I have already gotten the
I was working in Eclipse and used Subversive for versioning my program. However, now
The problem is - while program is working I change, add and delete data

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.