To convert a space-separated list into a list:#
list1 = input_list1.split()
Sets:#
# Convert into set to remove duplicates
set1 = set(list1)
# To find common values
common_values = set1.intersection(set2)
# Searching in set
seen = set()
if item in seen:
pass
# Adding a new item in set
seen.add(3)
Lists:#
# Appending a new item in list
list1.append(3)
# Accessing first element
list1[0]
# Accessing last element
list1[-1]
# Length of list
len(list1)
# Count elements satisfying a condition
count = sum([1 for s in input_list if len(s) >= 2 and s[0] == s[-1]])
# Sorted list
sorted_list = sorted(unsorted_list)
# Reverse sorted list
reverse_sorted_list = sorted(unsorted_list, reverse=True)
# Sorted dictionary by key
sorted_by_key = dict(sorted(dictionary1.items()))
# Reverse sorted dictionary by key
reverse_sorted_by_key = dict(sorted(dictionary1.items(), reverse=True))
# Sorted dictionary by value
sorted_by_value = dict(sorted(data.items(), key=lambda item: item[1]))
# Reverse sorted dictionary by value
reverse_sorted_by_value = dict(sorted(data.items(), key=lambda item: item[1], reverse=True))
# Remainder using %
remainder = a % b
# Decimal to octal
octal_value = oct(decimal_number)[2:]
# Octal to decimal
decimal_value = int('77', 8) # Output: 63 (7*8^1 + 7*8^0)
# String slicing
substring = str[start:end:step]
# List comprehension for prime numbers
prime_numbers = [n for n in range(11) if is_prime(n)]
# List comprehension example with filtering
fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
newlist = [x for x in fruits if "a" in x]
Math:#
# Volume of a sphere
volume = (4 / 3) * math.pi * (radius ** 3)
# List to tuple with index
tuples = [(i, x) for i, x in enumerate(input_list)]
Dictionary:#
# Key search in dictionary
if req in temp:
pass