0

I'm exercising dictionaries therefore I have the following

favorite_place = {
    'ppl1': {
        'person': 'josh',
        'places': ['Central park', 'Hollywood', 'Aspan']
    },
    'ppl2': {
        'person': 'mark',
        'places': ['Ands mountain', 'Himalaya mountain', 'Dead sea']
    },
    'ppl3': {
        'person': 'yossi',
        'places': ['times square', 'Osaka', ',McDonald\'s']
    },

}

for budy, places_info in favorite_place.items():
    ID = f"{budy}"
    PERSON_NAME = f"{places_info['person']}"
    PLACES = f"{places_info['places']}"
    print(f"\nPerson Identified by: {ID}\n"f"For {PERSON_NAME.title()}")
    print(f"The favorite places are:\n"f"\t",str(PLACES).strip('[]').replace('\'', ''))

output:

..................... ..................
Person Identified by: ppl3
For Yossi
The favorite places are:
     times square, Osaka, ", McDonald's"

How do I take this, for example:

 times square, Osaka, McDonalds

and make it to be like this -separated by a new line and with out the a comma??? :

times square
Osaka
McDonalds
Oren Rahav
  • 11
  • 1
  • 4
  • Stack Overflow is not intended to replace existing documentation and tutorials. Please repeat your materials on string processing and available methods. Also, please remove the inapplicable code from your posting: you ask only about changing the appearance of strings -- the dict portions don't seem to be part of your question at all. – Prune Jan 27 '21 at 01:13
  • 1
    pls see this - https://stackoverflow.com/questions/44780357/how-to-use-newline-n-in-f-string-to-format-output-in-python-3-6 – raj.andy1 Jan 27 '21 at 01:15
  • 1
    `PLACES = '\n'.join(places_info['places'])` – Nick Jan 27 '21 at 01:17
  • Does this answer your question? [How to use newline '\n' in f-string to format output in Python 3.6?](https://stackoverflow.com/questions/44780357/how-to-use-newline-n-in-f-string-to-format-output-in-python-3-6) – Nick Jan 27 '21 at 01:55
  • not that much, But somehow managed to pull this off – Oren Rahav Feb 03 '21 at 01:03

1 Answers1

0
favorite_place = {
    'ppl1': {
        'person': 'josh',
        'places': ['Central park', 'Hollywood', 'Aspan']
    },
    'ppl2': {
        'person': 'mark',
        'places': ['Ands mountain', 'Himalaya mountain', 'Dead sea']
    },
    'ppl3': {
        'person': 'yossi',
        'places': ['times square', 'Osaka', ',McDonald\'s']
    },

}

for budy, places_info in favorite_place.items():
    ID = budy
    PERSON_NAME = places_info['person']
    PLACES = places_info['places']
    print(f"\nPerson Identified by: {ID}\nFor {PERSON_NAME.title()}")
    print(f"The favorite places are:\n", '\n '.join([i for i in PLACES]))
itwasthekix
  • 585
  • 6
  • 11