within a dictionary, how do I remove a value from a key with multiple values? Python -


from collections import ordereddict  def main():     dictionary = ordereddict()     dictionary["one"] = ["hello", "blowing"]     dictionary["two"] = ["frying", "goodbye"]      key in dictionary:         print key, dictionary[key]      user_input = raw_input("remove buildings ending ing? y/n")     if user_input == ("y"):         print ""         key in dictionary:             x in dictionary[key]:                 if ("ing") in x or ("ing") in x:                     del dictionary[key][x]      print ""      key in dictionary:         print key, dictionary[key]  main() 

i attempting remove item "ing" in keys within dictionary, example "blowing" key "one" , "frying" key "two".

the resulting dictionary go this:

one ['hello', 'blowing'], 2 ['frying', 'goodbye'] 

to this:

one ['hello'], 2 ['goodbye'] 

dict comprehension.

return {x : [i in dictionary[x] if not i.lower().endswith('ing')] x in dictionary} 

edited replace values ending 'ing' 'removed'

return {x : [i if not i.lower().endswith('ing') else 'removed' in dictionary[x]] x in dictionary} 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -