Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

suggestions for Choosing a data structure for a friendship network

I have to implement a program which analyzes friendship. There will be a text file which will contain group of friends.so when user input a name from the group, the program shows who are this person’s friends.
For example, the text file contains,
Erina;Mira; Kyla;
If user inputs Mira it will show other person as her friends..
I need to store the text file data in a data structure.. So what kind of data structure will be suitable for this in python? Should I go for a dictionary??
( The question asks for nested data structure)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Yes a dictionary would be your best bet. You could store the name of the person as the key and the a list of friends as the value. You can then append friends to the list like this:

friends_dict = dict()
friends_dict['john'] = []
friends_dict['john'].append("lisa")
print(friends_dict)
$ {'john':['lisa']}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading