def phase1(p1, child, idx):
    """Phase a genotype given only one parents genotype.

    Arguments:
        p1 (string): genotype of parent  expressed in form 0/1, 0/0 etc
        child (string): genotype of child
        idx (integer): 0 or 1. If 0 then the allele inherited from the parent
                       appears to the left of | symbol in the phased genotype,
                       and to the right of the | symbol if idx is 1
    Returns:
        The phased genotype of the child if it is unambiguously resolvable.
        Otherwise the genotype is returned as is, i.e. unphased

    >>> phase1('0/1', '0/1', 0)
    '0/1'
    >>> phase1('0/2', '1/2', 0)
    '2|1'
    >>> phase1('0/3', '1/3', 1)
    '1|3'
    >>> phase1('./.', '0/1', 1)
    '0/1'
    >>> phase1('./.', './.', 0)
    './.'
    """
    #ca, _, cb = child
    ca, cb = child.split('/')
    if ca == '.':
        sep = '/'
    elif ca == cb and ca in p1:
        sep = '|'
    elif ca in p1 and cb not in p1:
        sep = '|'
    elif cb in p1 and ca not in p1:
        cb, ca = ca, cb
        sep = '|'
    else:
        sep = '/'
    if sep == '|' and idx == 1:
        ca, cb = cb, ca
    return ca + sep + cb