diff --git a/group.py b/group.py index e2ec347..32059a1 100644 --- a/group.py +++ b/group.py @@ -2,4 +2,47 @@ # Your code to go here... -my_group = +from statistics import mean + + +my_group = [ + { + 'name' : 'Jill', + 'age' : 26, + 'job' : 'biologist', + 'connections' : { + 'friend' : 'Zalika', + 'partner' : 'John' + } + }, + { + 'name' : 'Zalika', + 'age' : 28, + 'job' : 'artist', + 'connections' : { + 'friend' : 'Jill' + } + }, + { + 'name' : 'John', + 'age' : 27, + 'job' : 'writer', + 'connections' : { + 'partner' : 'Jill' + } + }, + { + 'name' : 'Nash', + 'age' : 34, + 'job' : 'chef', + 'connections' : { + 'cousin' : 'John', + 'landlord' : 'Zarika' + } + } +] + +print('The maximum age is ' + str(max(person['age'] for person in my_group))) +print('The mean number of relations is ' + str(mean(len(person['connections']) for person in my_group))) +print('The maximum age of people with at least one relation is ' + str(max(person['age'] for person in my_group if person['connections']))) +print('The maximum age of people with at least one friend is ' + str(max(person['age'] for person in my_group if 'friend' in person['connections']))) diff --git a/stretch_.py b/stretch_.py new file mode 100644 index 0000000..49d3ff7 --- /dev/null +++ b/stretch_.py @@ -0,0 +1,41 @@ +def forget(person1, person2): + # person1 is the main human who is forgetting person2 + for person in my_group: + if person['name'] == person1: + for connection in person['connections']: + if person['connections'][connection] == person2: + del person['connections'][connection] + break + +def add_person(name, age, job, connections): + my_group.append( + { + 'name' : name, + 'age' : int(age), + 'job' : job, + 'connections' : connections + } + ) + +def average_age(): + total = 0 + for person in my_group: + total += person['age'] + return total/len(my_group) + +my_group = [ + { + 'name' : 'Jill', + 'age' : 26, + 'job' : 'biologist', + 'connections' : { + 'friend' : 'Zalika', + 'partner' : 'John' + } + } +] + +forget('Jill', 'John') +add_person('Rachel', '22', '', {}) +print(my_group) +print(average_age()) \ No newline at end of file