Need help removing duplicates numbers in Python exercise -


i'm supposed write program eliminates duplicate values , returns unique numbers. must use def eliminate(alist) , def main(). numbers must entered standard input , must space separated.

the output should follow

enter numbers: 5 3 12 3 544 5 1 7 1

the numbers are: [5, 3, 12, 554, 1, 7]

instead get....

enter numbers: 5 3 12 3 544 5 1 7 1

the numbers are: ['5', ' ', '3', '1', '2', '4', '7']

how remove space? program doesn't recognize 554 single number, recognizes 5 4 4.

this got far

def eliminate(alist):     outlist = []     element in alist:         if element not in outlist:             outlist.append(element)     return outlist         def main():     numbers=input("enter numbers:")     alist=list(numbers)     print("the unique numbers are:",eliminate(alist)) main() 

please note: i'm not allow use set class program.

both of problems solved if used:

alist = numbers.split() 

instead of alist=list(numbers)

>>> numbers = '5 3 12 3 544 5 1 7 1' >>> alist = numbers.split() >>> alist ['5', '3', '12', '3', '544', '5', '1', '7', '1'] 

explanation:

if pass numbers list() function is, takes each character of string list member. way, '544' becomes ['5', '4', '4'] , '5 6' becomes ['5', '6'].

split() on other hand makes list of string splitting according specific delimiter, default, " " char.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -