How to create a list element which counts as a element but it should not have any value and while sorting the list it should be at last

Question:

How to create a list element which counts as element but dont have any value for its own, and also if we wanna sort that list that no value elements should go to last

How to create a list like this [1,2,_]

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        for i in range(0,len(nums)):
            for j in range(i+1,len(nums)):
                if nums[i] == nums[j]:
                    nums[i] = None
                    nums.sort(key=lambda e: (e is None, e))
                    break
        return set(nums)
Asked By: KARTX LEGEND YT

||

Answers:

It is simpler without looping:

res = [i if i not in nums[:n] else None for n, i in enumerate(nums)]
res.sort(key=lambda e: (e is None, e))
return res
Answered By: user19077881
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.