Как добавить данные в список словаря

 a = list(request.POST.getlist('users'))
 b = get_participants['participants']
 output=[]

        for i in b:
            for k in a:
                if k in i:
                    print(k)
                    c={
                    "participants" : k,
                    "attendance" : "Present"
                    }
                    # output.append(c)
                else:
                    c={
                    "participants" : i,
                    "attendance" : "Absent"
                    }
                output.append(c)
        print(output)

Это мой код

Мне нужно добавить участников с учетом их присутствия. В "a" я получаю список участников, которые присутствуют. В "b" я получаю всех участников

Моя логика была неправильной, пожалуйста, поправьте меня.

 a = list(request.POST.getlist('users'))
 b = get_participants['participants']
 output=[]

        for i in b:
            for k in a:
                if k in i:
                    print(k)
                    c={
                    "participants" : k,
                    "attendance" : "Present"
                    }
                    # output.append(c)
                else:
                    c={
                    "participants" : i,
                    "attendance" : "Absent"
                    }
                output.append(c)
        print(output)

Я пробовал следующее Output: [{'participants': 'rajesh.gupta@atmstech.in', 'посещаемость': 'Присутствует'}, {'participants': 'rajesh.gupta@atmstech.in', 'посещаемость': 'Отсутствует'}, {'participants': 'pranay.gharge@atmstech.in', 'посещаемость': 'Отсутствует'}, {'participants': 'pranay.gharge@atmstech.in', 'посещаемость': 'Присутствует'}]

Ожидаемый результат: [{'participants': 'rajesh@gamil.in', 'посещаемость': 'Присутствует'}, {'участники': 'pranay@gmail.in', 'посещаемость': 'Присутствует'}]

Вернуться на верх