def key_update(key, bibcode, alternate_bibcode):
    """
  Update key with year and journal of arxiv version of a key.

  This function will search and update the year in a key,
  and the journal if the key contains the word 'arxiv' (case
  insensitive).

  The function extracts the info from the old and new bibcodes.
  ADS bibcode format: http://adsabs.github.io/help/actions/bibcode

  Examples
  --------
  >>> import bibmanager.ads_manager as am
  >>> key = 'BeaulieuEtal2010arxivGJ436b'
  >>> bibcode           = '2011ApJ...731...16B'
  >>> alternate_bibcode = '2010arXiv1007.0324B'
  >>> new_key = am.key_update(key, bibcode, alternate_bibcode)
  >>> print(f'{key}\\n{new_key}')
  BeaulieuEtal2010arxivGJ436b
  BeaulieuEtal2011apjGJ436b

  >>> key = 'CubillosEtal2018arXivRetrievals'
  >>> bibcode           = '2019A&A...550A.100B'
  >>> alternate_bibcode = '2018arXiv123401234B'
  >>> new_key = am.key_update(key, bibcode, alternate_bibcode)
  >>> print(f'{key}\\n{new_key}')
  CubillosEtal2018arXivRetrievals
  CubillosEtal2019aaRetrievals
  """
    old_year = alternate_bibcode[0:4]
    year = bibcode[0:4]
    if old_year != year and old_year in key:
        key = key.replace(old_year, year, 1)
    journal = bibcode[4:9].replace('.', '').replace('&', '').lower()
    ijournal = key.lower().find('arxiv')
    if ijournal >= 0:
        key = ''.join([key[:ijournal], journal, key[ijournal + 5:]])
    return key
