Recommand · November 2, 2021 0

Python class return varius

How to make varius return looking at the how much Group.create_group_from_file(file) or maybe if we dont print must return long str then if we print must return small string but i dont know best idea for solution

def create_group_from_file(self, students_file: str):
    title = students_file[:-5]
    groups = []
    with open(students_file) as file:
        users = json.load(file)
    if isinstance(users, list):
        for i in range(len(users)):
    dict_with_groups = {
        "title": title,
        "students": groups

    return dict_with_groups
g1 = Group.create_group_from_file("2020_2.json")
print(g1)---> must return 2020_2: ["Student 1 from second Group (98): ['Python']", "Student 2 from second Group (70.34): ['Ruby', 'Python', 'Frontend development']"]
g1 = Group.create_group_from_file("2020_2.json")
g2 = Group.create_group_from_file("2020-01.json")
>>>[{"title": "2020_2", "students": [{"full_name": "Student 1 from second Group", "avg_rank": 98, "courses": ["Python"]}, {"full_name": "Student 2 from second Group", "avg_rank": 70.34, "courses": ["Ruby", "Python", "Frontend development"]}]}, {"title": "2020-01", "students": [{"full_name": "Student2 from group2", "avg_rank": 50.4, "courses": ["C++"]}]}]