python3答案_python的问题,是python3以上的,求答案

Question1[3marks]Writeafunctionthatreturnsanewlistbyeliminatingtheduplicatevaluesinthelist.Usethefollowingfunctionheader:defeliminate_duplicates(my_list):Writeamainfuncti...

Question 1 [3 marks]

Write a function that returns a new list by eliminating the duplicate values in the list. Use the following function header:

def eliminate_duplicates(my_list):

Write a main function that reads in numbers separated by a space in one line, changes the string to a list of integers, calls the function (eliminate_duplicates) and finally displays the result list returned by the function, as well as the unmodified original list of values. Here is the sample output:

Sample Output

Enter numbers: 2 3 77 3 2 1 7 1

The distinct numbers are: [2, 3, 77, 1, 7]

The original numbers are: [2, 3, 77, 3, 2, 1, 7, 1]

Another Sample Output:

Enter numbers: 44 76 44 34 98 34 1 44 99 1 1 1

The distinct numbers are: [44, 76, 34, 98, 1, 99]

The original numbers are: [44, 76, 44, 34, 98, 34, 1, 44, 99, 1, 1, 1]

NOTE:

The set class in Python represents objects that are unordered collection of unique elements. The order of the output must match the sample output, and so you cannot use the set class for this question.

You may assume that the user always enters a list of integer numbers separated by spaces. Input validation is not required.

The template for the program is as follows:

def eliminate_duplicates(my_list):

# Write the function code here

def main():

# Write the main function

# Call the main function

main()

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值