python - Why can't I print a returned value? -


i've written code, , want able use dictionary created in function argument function can't seem print on it's own, or use argument 'names not defined'. how create same output (a list of dictionaries dictionaries values) being able use dictionary outside of function?

def get_name(string_input):     l = [line.split('is connected to') i, line in enumerate(string_input.split('.')) if % 2 == 0]     names = {name[0]:{} name in l}     return names  print get_name(example_input)  print names 

you must assign returned value

names = get_name(example_input)  print names 

the variable names used inside function local, not visible outside.


Comments