1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Function to merge unique values from multiple lists to one list

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to write a function that will merge unique values in separate lists into one list. I keep getting a result of a tuple of lists. Ultimately I would like to have one list of unique values from my three lists -a,b,c.

    def merge(*lists):
    newlist = lists[:]
    for x in lists:
    if x not in newlist:
    newlist.extend(x)
    return newlist

    a = [1,2,3,4]
    b = [3,4,5,6]
    c = [5,6,7,8]

    print(merge(a,b,c))


    I am getting a Tuple of Lists

    ([1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8])

    Continue reading...

Compartilhe esta Página