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

后端 未结 5 1768
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:20

    def distinct(lst):
        dlst = []
        for val in lst:
            if val not in dlst:
                dlst.append(val)
        return dlst
    

提交回复
热议问题