Skip to content

Instantly share code, notes, and snippets.

@Bovojon
Created October 19, 2017 17:45
Show Gist options
  • Save Bovojon/c3e5dc7f1798d3518f19ac40532b6587 to your computer and use it in GitHub Desktop.
Save Bovojon/c3e5dc7f1798d3518f19ac40532b6587 to your computer and use it in GitHub Desktop.
Given requests to add users to a group, output a list of the members of each group.
'''
Given requests to add users to a group, output a list of the members of each group.
'''
def listMembers(string_list):
'''
We could automate the creation of a new group that is not in the
alphabetically ordered list of groups yet. However, I believe that is beyond
the scope of what this assignment is asking for.
'''
if string_list == '':
print("Please provide a list of the users")
else:
groups_list = [["admins"], ["students"], ["teachers"]]
string_list= string_list.lower()
users_list = string_list.split("\n")
for user in users_list:
name_and_group = user.split()
if name_and_group[1] == "admins":
groups_list[0].append(name_and_group[0])
elif name_and_group[1] == "students":
groups_list[1].append(name_and_group[0])
elif name_and_group[1] == "teachers":
groups_list[2].append(name_and_group[0])
for group in groups_list:
names = group[1:]
names.sort()
string_names = ""
for i in range(len(names)):
string_names += names[i]
if i != (len(names) - 1):
string_names += ","
print group[0],",",string_names
if __name__ == '__main__':
listMembers("Zlan admins\nbeth students\ncharlie TEachers\ndavid admins")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment