• May 5, 2026 •CodeCatch
0 likes • 7 views
• Jun 1, 2023 •CodeCatch
0 likes • 5 views
filename = "data.txt" with open(filename, "r") as file: file_contents = file.readlines() file_contents = [line.strip() for line in file_contents] print("File contents:") for line in file_contents: print(line)
• Oct 23, 2026 •zsq1364202622-89e7
0 likes • 3 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
• Oct 15, 2022 •CodeCatch
1 like • 3 views
my_list = ["blue", "red", "green"] #1- Using sort or srted directly or with specifc keys my_list.sort() #sorts alphabetically or in an ascending order for numeric data my_list = sorted(my_list, key=len) #sorts the list based on the length of the strings from shortest to longest. # You can use reverse=True to flip the order #2- Using locale and functools import locale from functools import cmp_to_key my_list = sorted(my_list, key=cmp_to_key(locale.strcoll))
• Oct 7, 2022 •KETRICK
0 likes • 1 view
import pandas as pd x = pd.read_excel(FILE_NAME) print(x)
• Sep 6, 2020 •C S
def Fibonacci(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==1: return 0 # Second Fibonacci number is 1 elif n==2: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) # Driver Program print(Fibonacci(9))