• Oct 23, 2026 •zsq1364202622-89e7
0 likes • 2 views
def remove_repeated_blocks(content_list: list[str], line_count: int) -> list[str]: """删除相邻重复的代码块,保留第一次出现的内容。""" if line_count <= 0: return content_list result = [] seen = set() i = 0 while i < len(content_list): block = tuple(line.strip() for line in content_list[i:i + line_count]) if len(block) < line_count: result.extend(content_list[i:]) break if block in seen: i += line_count continue seen.add(block) result.extend(content_list[i:i + line_count]) i += line_count return result
• Nov 18, 2022 •AustinLeath
0 likes • 3 views
# List lst = [1, 2, 3, 'Alice', 'Alice'] # One-Liner indices = [i for i in range(len(lst)) if lst[i]=='Alice'] # Result print(indices) # [3, 4]
• May 31, 2023 •CodeCatch
def generate_pascals_triangle(num_rows): triangle = [] for row in range(num_rows): # Initialize the row with 1 current_row = [1] # Calculate the values for the current row if row > 0: previous_row = triangle[row - 1] for i in range(len(previous_row) - 1): current_row.append(previous_row[i] + previous_row[i + 1]) # Append 1 at the end of the row current_row.append(1) # Add the current row to the triangle triangle.append(current_row) return triangle def display_pascals_triangle(triangle): for row in triangle: for number in row: print(number, end=" ") print() # Prompt the user for the number of rows num_rows = int(input("Enter the number of rows for Pascal's Triangle: ")) # Generate Pascal's Triangle pascals_triangle = generate_pascals_triangle(num_rows) # Display Pascal's Triangle display_pascals_triangle(pascals_triangle)
• Sep 9, 2023 •AustinLeath
0 likes • 28 views
print("test")
• Dec 29, 2025 •CodeCatch
0 likes • 10 views
def bitonic_sort(arr, low, cnt, direction): ...
# Prompt user for base and height base = float(input("Enter the base of the triangle: ")) height = float(input("Enter the height of the triangle: ")) # Calculate the area area = (base * height) / 2 # Display the result print("The area of the triangle is:", area)