Retrieves timezone choices from any iterable (normally pytz).

def get_choices(timezones, grouped=False):
    """Retrieves timezone choices from any iterable (normally pytz)."""

    # Created a namedtuple to store the "key" for the choices_dict
    TZOffset = namedtuple('TZOffset', 'value offset_string')

    choices_dict = defaultdict(list)

    # Iterate through the timezones and populate the timezone choices
    for tz in iter(timezones):
        # Retrieve a datetime object in this time zone
        now = datetime.now(pytz.timezone(tz))

        # Retrieve the timezone offset ("-0500" / "+0500")
        offset = now.strftime("%z")

        # Retrieve the offset string ("GMT-12:00" / "GMT+12:00")
        timezone_offset_string = 'GMT{plus_minus}{hours}:{minutes}'.format(
            **TIMEZONE_OFFSET_REGEX.match(offset).groupdict()
        )

        if not grouped:
            # Format the timezone display string
            display_string = '({timezone_offset_string}) {tz}'.format(
                timezone_offset_string=timezone_offset_string,
                tz=tz,
            )
        else:
            display_string = tz

        choices_dict[
            TZOffset(value=int(offset), offset_string=timezone_offset_string)
        ].append(
            (tz, display_string)
        )

    choices = []

    for tz_offset in sorted(choices_dict, key=attrgetter('value')):
        if not grouped:
            choices.extend(
                tuple(choices_dict[tz_offset])
            )
        else:
            choices.append(
                (
                    tz_offset.offset_string,
                    tuple(choices_dict[tz_offset])
                )
            )

    # Cast the timezone choices to a tuple and return
    return tuple(choices)