def get_lang_switch(pvs, wikidbs=(), ref_match=False):
    """Get pairs of page views that are language switches.

    Parameters:
        pvs: list of page view objects for a given reader's session
        wikidbs: if empty, all language switches return. Otherwise, only language switches that involve languages
                    included in wikidbs will be retained.
    Returns:
        switches: list of tuples, where each tuple corresponds to two page views of a single Wikidata item
                    across two different projects.
                    If a session is:
                    [(dt='2019-02-16T11:31:53', proj='enwiki', title='Columbidae', wd='Q10856'),
                     (dt='2019-02-16T11:32:05', proj='enwiki', title='Anarchism', wd='Q6199'),
                     (dt='2019-02-16T11:32:13', proj='eswiki', title='Columbidae', wd='Q10856')]
                    Then the switches would be of the form [(0, 2)]
    """
    switches = []
    # at least two different projects viewed in the session
    if len(set([p.proj for p in pvs])) > 1:
        # find all wikidata items viewed in multiple languages
        # preserve which one was viewed first
        for i in range(0, len(pvs) - 1):
            for j in range(i+1, len(pvs)):
                diff_proj = pvs[i].proj != pvs[j].proj
                same_item = pvs[i].wd and pvs[i].wd == pvs[j].wd
                if diff_proj and same_item:
                    if not wikidbs or pvs[i].proj in wikidbs or pvs[j].proj in wikidbs:
                        if ref_match:
                            if pvs[i].proj == pvs[j].referer:
                                switches.append((i, j))
                        else:
                            switches.append((i, j))
                        break
    return switches