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

The Archive Base Latest Questions

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

Possible Duplicate: How do you check if list is blank? def CleanWhiteSpace(theDict) : stuff=[]

  • 0

Possible Duplicate:
How do you check if list is blank?

def CleanWhiteSpace(theDict) :
    stuff=[]

    for key,value in theDict.items():
        for d in value:
            if value != " ":
                stuff.append(d)    
                print d
                theDict[key]=stuff
            if not value[d]:
                print value
        stuff=[]
    return theDict
print CleanWhiteSpace({'a':['1','2'],'b':['3',' '],'c':[]})

how do u check is c is blank is c is simply equal to []?

okay I have a DICTIONARY that has LISTS inside it, some of these lists are composed of NOTHING. I need to loop though the dictionary and remove those keys that have the value of AN EMPTY LIST.

trying to be as clear as possible. what have i tried? i have tried multiple different methods to check if the value of the key is equal to nothing. i tried the value == “”: statement, i tried the, len function to check if the value is empty, i tried if value: nothing seems to work, why? because as someone answered, empty lists don’t get executed in the body of the loop

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

    In your example, when key c is being processed the value of key will be 'c' and the value of value will be [], an empty list. You can test for this by saying, e.g., if not value:. Or, if you know it’s a list rather than some other kind of sequence, if value==[].

    It’s hard to be sure from the question as written, but did you perhaps try putting something like if d==[]: somewhere inside the loop? That won’t work, because when value is an empty list the loop for d in value: is looping over the elements of an empty list, and there aren’t any, so the loop body will never be executed.

    Incidentally, some other bits of your code seem to show confusion between value and its elements. For instance, you write if value != " " but surely it’s d that you want to be testing there. And what’s with if not value[d]:? Why would you expect d to be a suitable thing to index value by?

    You should also think a bit more carefully about what happens to stuff as your code executes.

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

Sidebar

Related Questions

Possible Duplicate: Check if a List already contains an item or not? for (int
Possible Duplicate: Check if all items are the same in a List I have
Possible Duplicate: Python: What is the best way to check if a list is
Possible Duplicate: How to check if an array value exists I have a problem
Possible Duplicate: Swap two items in List<T> Edit: Maybe this will work for getting
Possible Duplicate: Check if a variable contains a numerical value in Javascript? How do
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Check that an email address is valid on iOS What is the
Possible Duplicate: Check if a variable is empty Simple PHP question: I have this
Possible Duplicate: Check synchronously if file/directory exists in Node.js For example, i have a

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.