Write a function to reverse a string.
def reverse_string(input_str):
return input_str[::-1]
Example:
reverse_string('hello') # Output: 'olleh'
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。
了解热门 Python Coding 面试题与答案,帮助应届生和有经验的候选人为求职面试做好准备。
了解热门 Python Coding 面试题与答案,帮助应届生和有经验的候选人为求职面试做好准备。
搜索问题以查看答案。
def reverse_string(input_str):
return input_str[::-1]
Example:
reverse_string('hello') # Output: 'olleh'
收藏此条目、标记为困难题,或将其加入复习集合。
def is_palindrome(input_str):
return input_str == input_str[::-1]
Example:
is_palindrome('radar') # Output: True
收藏此条目、标记为困难题,或将其加入复习集合。
def is_leap_year(year):
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
Example:
is_leap_year(2024) # Output: True
收藏此条目、标记为困难题,或将其加入复习集合。
def find_max_element(lst):
return max(lst)
Example:
find_max_element([3, 7, 2, 8, 5]) # Output: 8
收藏此条目、标记为困难题,或将其加入复习集合。
from collections import Counter
def count_occurrences(lst):
return Counter(lst)
Example:
收藏此条目、标记为困难题,或将其加入复习集合。
def is_anagram(str1, str2):
return sorted(str1) == sorted(str2)
Example:
收藏此条目、标记为困难题,或将其加入复习集合。
def remove_duplicates(lst):
return list(set(lst))
Example:
收藏此条目、标记为困难题,或将其加入复习集合。