User Tools

Site Tools


get_unique_items_in_a_list

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
get_unique_items_in_a_list [2021/07/23 21:54] – [Task] rajuget_unique_items_in_a_list [2021/07/23 22:14] – [Task] raju
Line 5: Line 5:
 mylist = ['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow'] mylist = ['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
 </code> </code>
-get the list of unique items. This can be one of three ways:+get the list of unique items. The output can be one of three ways:
   - Order does not matter. <code>   - Order does not matter. <code>
 ['thenandnow', 'debate', 'nowplaying', 'PBS', 'job'] ['thenandnow', 'debate', 'nowplaying', 'PBS', 'job']
 </code> </code>
-  - Preserve the order and keep the first unique one. <code>+  - Preserve the order and keep the first unique item. <code>
 ['nowplaying', 'PBS', 'job', 'debate', 'thenandnow'] ['nowplaying', 'PBS', 'job', 'debate', 'thenandnow']
 </code> </code>
-  - Preserve the order and keep the last unique one. <code>+  - Preserve the order and keep the last unique item. <code>
 ['PBS', 'nowplaying', 'job', 'debate', 'thenandnow'] ['PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
 </code> </code>
  
-Assume Python >= 3.is used+==== Notes and assumptions ==== 
 +  * Assume Python >= 3.is used
 +  * Starting from Python 3.7, dictionaries in python are ordered by insertion order. Per https://docs.python.org/3.7/tutorial/datastructures.html#dictionaries <code> 
 +Performing list(d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order 
 +</code>
  
 ==== Case 1: unique unordered ==== ==== Case 1: unique unordered ====
get_unique_items_in_a_list.txt · Last modified: 2021/07/23 22:14 by raju