Combine single and multi argument variables in a function call for Python -


i wrote following function return subset of dictionary want insist on having @ least 1 key provided in input arguments.

def getproperty(self,x, *key):     key = [k k in key]     key.insert(0,x)     return {k:self.__properties[k] k in key if k in self.__properties} 

the code works.

i know insert not necessary since dictionary elements aren't ordered. wish rid of first for-loop creates list extracting elements multi-argument tuple.

something like

key = [x] + [key] 

but not work.

this should need:

def getproperty(self,x, *key):     key = (x,)+key     return {k:self.__properties[k] k in key if k in self.__properties} 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -