How can I write a list without duplicate with only for, if and boolean

后端 未结 5 1769
Happy的楠姐
Happy的楠姐 2021-01-15 20:46

My professor gave me an exercise where I write a function that returns a list without the duplicate to the old list. This is the code but I don\'t know how to write the meth

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-15 21:29

    Is this considered cheating?

    >>> distinct = lambda lst: list(set(lst))
    >>> distinct([1,3,1,2,6])
    [1, 2, 3, 6]
    >>> distinct(['a','ab','a','ab'])
    ['a', 'ab']
    

提交回复
热议问题