Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:15:12+00:00 2026-06-13T20:15:12+00:00

New to python-can someone tell me what I am doing wrong? I need to

  • 0

New to python-can someone tell me what I am doing wrong?

I need to write a function that takes unknown number of arguments and returns a unique list.
For example:

a= ['mary', 'james', 'john', 'john']
b= ['elsie', 'james', 'elsie', 'james']

unique_list(a,b)

['mary', 'james','john', 'elsie']

This is some of the code I have after doing some research but the output is not what I need:

def unique_list:(*something)
    result1= list(something)
    result = ' '.join(sum(result1, []))
    new= []
    for name in result:
            if name not in new:
                           new.append(name)
    return new
       
>>> unique_list(a,b)
['m', 'a', 'r', 'y', ' ', 'j', 'e', 's', 'o', 'h', 'n', 'l', 'i']

This is another one I have tired:

def unique_list(*something):
    result= list(something) 
    new=[]
    for name in result:
        if name not in new:
            new.append(name)
    return new
>>> unique_list(a,b)
[['mary', 'james', 'john', 'john'], ['elsie', 'james', 'elsie', 'james']]

Another one but I got an error message:

def single_list(*something):
    new=[]
    for name in something:
        if name not in new:
            new.append(name)
    new2= list(set(new))
    return new2
>>> single_list(a,b)
Traceback (most recent call last):
  File "", line 1, in 
    single_list(a,b)
  File "", line 6, in single_list
    new2= list(set(new))
TypeError: unhashable type: 'list'

Any ideas? Thank you in advance for all your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:15:13+00:00Added an answer on June 13, 2026 at 8:15 pm

    You can concatenate all the lists and then create a set from this resulting list. This will work for any number of passed in lists where the function looks like def unique_lists( *lists )

    ret_list = []
    for l in lists:
        ret_list = ret_list + l
    
    return set( ret_list )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to python programming..can someone suggest some way to do the following:
I'm new to python and came across this segment of code. Can someone help
Can someone tell me which are the main differences, or aspects that I should
I'm very new to Python and Django so maybe someone can point me in
Very new to python and can't understand why this isn't working. I have a
I'm new to python and pylons although experienced in PHP. I'm trying to write
Can someone tell me real quick how you set up a Django environment on
Keep in mind that I am still very new to python coding as I
I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1.
I'm a new Python programmer who is having a little trouble using 'self' in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.