generate functionThu, 09 Mar 2023

Q,W,E,R,T,Y,U,I,O,P,A,S,D,F are 14 members belongs to G1,G2 and G3 following G1(Q,W,E,R,T) G2(Y,U,I,O,P,A) and G3(S,D,F) are 3 groups with 14 members in total and get 7 members out of each groups without repeating and where you can select only ( max 3 or 1 member from G1),(max 4 and min 2 from G2) and ( max 2 and min 1 from G3)

def get_member_list(lst, number_of_member): return random.sample(lst, number_of_member) def get_group_members(members, number_of_member): grp_members = [] for i in members: grp_members.append(get_member_list(i, number_of_member[members.index(i)])) return grp_members members = [['Q','W','E','R','T'],['Y','U','I','O','P','A'],['S','D','F']] number_of_member = [3,4,2] print(get_group_members(members, number_of_member))

Questions about programming?Chat with your personal AI assistant