Tuesday, 15 May 2012

How to get my hashmap to return multiple values to one key in python -


I'm at the end of my intelligence. I'm learning Python from learning PythontheHardWay, I was doing good practice until 39 Use dictionary module with swap I can only get it to work with key, price pairs. I want this module to be able to work with multiple values ​​for each key. There was another question like this, but the answer was not entirely complete, or I could not understand the answer. I want to learn the dragon, but it is really banning me from progress and I need help.

  def (mapped, key, default = none): "" The value is given in a bucket for the given key, or the default "" bucket = mill_bet (one map, key ) I, k, v = get_slot (aMap, key, default = default) for kum in enumerate (bucket): while v: return v # value of back key !!!  

This module does not retrieve the function. I use the list function of Python to list the entire dictionary with several key values. So I know that the values ​​through my set function are:

  def set (aMap, key, value): "" sets the key for the value, Instead of any existing value, "bucket = gets (one map, key) I, k, v = get_slot (one map, key) bucket. Append ((key, value))  

I know that I should get a value list there and then loop through the list if the key should have more than one value

put me in code language There is a hard time doing the bucket in the list for the tuple (K, V) pairs and there should be a list of V in Kashmir.

By now I see only one value and it closes why the loop closes?

Thanks

EDIT: For more clarity, I want to return more than one value if I input more than one value. Hashap (city, 'mh', 'mumbai') hashp .Set (city, 'mh', 'Pune') hashp .Set (city, ' ("% S"% Hashp.

All these values ​​should be excluded.

Keep in mind that the keyword " Back " always eliminates the function (cali) and jumps to the caller, Strong> back can not multiple return keywords using value multiple times "

    1. A list Return to the Tupal (as suggested @ terry-jane-riddy)
  • as applicable Do

    No comments:

    Post a Comment