Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to unique list in python

import numpy as np

def unique(list1):
    npArray1 = np.array(list1)
    uniqueNpArray1 = np.unique(npArray1)
    return uniqueNpArray.tolist()
  
list1 = [10, 20, 10, 30, 40, 40]
unique(list1) # [10, 20, 30, 40]
Comment

generate unique list

"""Generation of unique random list of size n
"""
from random import sample
def unique_lst(n):
    return sample(range(10, 100), n) # return a sample of lst (unique lst)
    
# print(unique_lst(10))
Comment

unique items in a list python

list(dict.fromkeys(list_with_duplicates))
Comment

PREVIOUS NEXT
Code Example
Python :: get all permutations of string 
Python :: python divide all values in list 
Python :: flatten list in python 
Python :: how to stop python for certain time in python 
Python :: lru cache 
Python :: scapy get packet source ip address python 
Python :: python time a task 
Python :: string remove ,replace, length in python 
Python :: django table view sort filter 
Python :: python get substring 
Python :: check if a number is in a list python 
Python :: python django adding category 
Python :: 151 - Power Crisis solution 
Python :: python - subtracting dictionary values 
Python :: exception logging 
Python :: python := 
Python :: wordcount pyspark 
Python :: how to comment python 
Python :: container with most water python code leetcode 
Python :: python zip 
Python :: split df coliumn 
Python :: convert timestamp to period pandas 
Python :: Align axis labels in subplots 
Python :: management command in django 
Python :: fonction nombre premier python 
Python :: assigning crs using python pyproj 
Python :: how to run mac terminal from python script 
Python :: xlrd python read excel 
Python :: if in one line python 
Python :: python get element by index 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =