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

后端 未结 5 1766
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:25

    If order isn't important, you can cast it to a set, then back to a list

    def distinct(lst):
        return list(set(lst))
    

提交回复
热议问题