<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def AddGroupMemberships(self):
 """Adds aggregate group membership from group, gshadow and passwd."""

    self.groups = {g.name: self._Members(g) for g in itervalues(self.groups)}
    # Map the groups a user is a member of, irrespective of primary/extra gid.
    for g in itervalues(self.groups):
      for user in g.members:
        membership = self.memberships.setdefault(user, set())
        membership.add(g.gid)
    # Now add the completed membership to the user account.
    for user in itervalues(self.entry):
      user.gids = self.memberships.get(user.username)