Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sort list case insensitive

# Basic syntax:
sorted(your_list, key=str.lower)
# Where:
#	- the key parameter specifies a function (or other callable) that is
#		called on each list element prior to making comparisons. Here, we
#		sort your_list as though all the elements were lowercase

# Example usage 1:
your_list = ["Z", "zebra", "A", "apple"]
sorted(your_list) # without key
--> ['A', 'Z', 'apple', 'zebra']

sorted(your_list, key=str.lower) # with key
--> ['A', 'apple', 'Z', 'zebra']

# Example usage 2:
# Say you want to sort the keys of a dictionary by their last letter:
your_dictionary = {'this': 3, 'example': 4, 'be': 5, 'banana': 1}
sorted(your_dictionary.keys(), key=lambda i: i[-1])
--> ['banana', 'example', 'be', 'this']
Comment

PREVIOUS NEXT
Code Example
Python :: set index pandas 
Python :: python launch prompt 
Python :: string without space pythonm 
Python :: fluffy ancake recipe 
Python :: data type of none in python 
Python :: how to convert uppercase to lowercase and vice versa in python 
Python :: example exponential distribution python 
Python :: == in python 
Python :: how to swap numbers in python mathematically 
Python :: csv to pdf python 
Python :: python daemon 
Python :: import messages 
Python :: what mean import in python 
Python :: python schleife 
Python :: python code to calculate encryption time 
Python :: python convert integer to signed base 2 complement 
Python :: hwo to syntax in python 
Python :: if a or b in python 
Python :: nested input python 
Python :: Computation failed in `stat_flow()`: 
Python :: keylogger to exe 
Python :: 12 hour clock to 24 hour clock in python 
Python :: how to update pip in python 
Shell :: how to delete dangling docker images 
Shell :: git update gitignore 
Shell :: ubuntu install gimp 
Shell :: how to kill a process on a port? 
Shell :: ubuntu disabling IPV6 
Shell :: install pymysql 
Shell :: gyp: No Xcode or CLT version detected! 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =