<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def load_friend_chains(chain, friend_chains, txt, nfiles=None):
 """Load a list of trees from a file and add them as friends to the chain."""


    if re.search('.root?', txt) is not None:
        c = ROOT.TChain(chain.GetName())
        c.SetDirectory(0)
        c.Add(txt)
        friend_chains.append(c)
        chain.AddFriend(c, rand_str())
        return

    files = np.loadtxt(txt, unpack=True, dtype='str')
    if files.ndim == 0:
        files = np.array([files])
    if nfiles is not None:
        files = files[:nfiles]
    print("Loading %i files..." % len(files))

    c = ROOT.TChain(chain.GetName())
    c.SetDirectory(0)
    for f in files:
        c.Add(f)
    friend_chains.append(c)

    chain.AddFriend(c, rand_str())
    return