import itertools
import re
from typing import Iterable, Iterator, Any


def get_temperature(text: str) -> float:
    temp_re = re.compile(r'(\d+(?:[.p]\d*)?)\s*K')
    m = temp_re.search(text)
    if m is not None:
        return float(m.group(1))

    else:
        m = re.search('RT', text)
        if m is not None:
            return 300.0

    return -1.


def staggered_range(list_in: Iterable, stepsize: int = 2) -> Iterator[Any]:
    return itertools.chain(*[list_in[i::stepsize] for i in range(stepsize)])


def roundrobin(*iterables):
    """
    Taken from the itertools recipes
    """
    num_active = len(iterables)
    nexts = itertools.cycle(iter(it).__next__ for it in iterables)
    while num_active:
        try:
            for next in nexts:
                yield next()
        except StopIteration:
            # Remove the iterator we just exhausted from the cycle.
            num_active -= 1
            nexts = itertools.cycle(itertools.islice(nexts, num_active))
