Run
def split_string(x, N): # Calculate the length of each part part_size = len(x) // N # Initialize a list to store the parts parts = [] # Iterate through the string and split it into equal parts for i in range(0, len(x), part_size): part = x[i:i+part_size] parts.append(part) return parts # Input string x = "abcdefghijklmno" # Number of parts to split the string into N = 5 # Split the string into N equal parts result = split_string(x, N) # Print the results for i, part in enumerate(result): print(f"Part {i+1}: {part}")
Output