def put_team(self, org, team_name, read_only, members):
        """Create a team in a github organization.

        Utilize
        https://developer.github.com/v3/orgs/teams/#list-teams,
        https://developer.github.com/v3/orgs/teams/#create-team,
        https://developer.github.com/v3/orgs/teams/#list-team-members,
        https://developer.github.com/v3/orgs/teams/#add-team-membership,
        and
        https://developer.github.com/v3/orgs/teams/#remove-team-membership.
        to create a team and/or replace an existing team's membership
        with the ``members`` list.

        Args:
            org (str): Organization to create the repo in.
            team_name (str): Name of team to create.
            read_only (bool): If false, read/write, if true read_only.
            members (list): List of github usernames to add to the
                              team. If none, membership changes won't occur

        Raises:
            GitHubUnknownError
            requests.RequestException

        Returns:
            dict: The team dictionary
                (https://developer.github.com/v3/orgs/teams/#response-1)

        """
        # Disabling too-many-locals because I need them as a human to
        # keep track of the sets going on here.
        # pylint: disable=too-many-locals
        try:
            team_dict = self._find_team(org, team_name)
        except GitHubNoTeamFound:
            team_dict = self._create_team(org, team_name, read_only)

        # Just get the team and exit if no members are given
        if members is None:
            return team_dict

        # Have the team, now replace member list with the one we have
        members_url = '{url}teams/{id}/members'.format(
            url=self.api_url,
            id=team_dict['id']
        )
        existing_members = self._get_all(members_url)

        # Filter list of dicts down to just username list
        existing_members = [x['login'] for x in existing_members]

        # Grab everyone that should no longer be members
        remove_members = dict(
            [(x, False) for x in existing_members if x not in members]
        )
        # Grab everyone that should be added
        add_members = dict(
            [(x, True) for x in members if x not in existing_members]
        )
        # merge the dictionary of usernames dict with True to add,
        # False to remove.
        membership_dict = dict(
            chain(remove_members.items(), add_members.items())
        )
        # Now do the adds and removes of membership to sync them
        for member, add in membership_dict.items():
            url = '{url}teams/{id}/memberships/{member}'.format(
                url=self.api_url,
                id=team_dict['id'],
                member=member
            )
            if add:
                response = self.session.put(url)
            else:
                response = self.session.delete(url)

            if response.status_code not in [200, 204]:
                raise GitHubUnknownError(
                    'Failed to add or remove {0}. Got: {1}'.format(
                        member, response.text
                    )
                )

        return team_dict
dataset/ETHPy150Open mitodl/orcoursetrion/orcoursetrion/lib/github.py/GitHub.put_team/original