A
A
Artur Kudashev2018-10-30 18:42:34
Python
Artur Kudashev, 2018-10-30 18:42:34

How to pass a dictionary name to a function?

Good afternoon. There was a problem with kwargs in Python, I searched the Internet, but did not find the answer. When calling the function, python gives an error that it expects 0 arguments, and 1 is passed. If I pass the dictionary itself instead of the name of the dictionary, then there are no errors, but I would like to pass exactly the name of the dictionary. Explain what is wrong. Thanks in advance :)

people = {
  'josh': 'man',
  'jack': 'man',
  'anna': 'woman'
}

def people(**kwargs):
  for name, sex in kwargs.items():
    print(name + ' is a ' + sex)

people(people)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2018-10-30
@dmtrrr

people(**people)

T
Talgat Baltasov, 2015-09-11
@lynnikvadim

how are these arrays related?

A
Alexander, 2015-09-11
@BeVirtual

and the standard <?print_r($array)?> doesn't work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question