安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技

1编写一个字符串处理函数函数的输入参数为由若干不相连的英文逗号分隔的字符串例如交大西直门天安门函数的返回值是一个列表它的元素是由每个逗号前后不含逗号的字符组成的元组

  • 日期: 2025-01-04 11:11:29
  • 标签: 教育

def process_string(string): string_list = string.split(",") result_list = [] for s in string_list: s = s.strip() if s: result_list.append(tuple(s.split())) return result_list

测试

print(process_string("交大,西直门,天安门"))

输出 [('交大',), ('西直门',), ('天安门',)]

1编写一个字符串处理函数函数的输入参数为由若干不相连的英文逗号分隔的字符串例如交大西直门天安门函数的返回值是一个列表它的元素是由每个逗号前后不含逗号的字符组成的元组

原文地址: https://www.cveoy.top/t/topic/bYzu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: 编写一个字符串处理函数函数的输入参数为由若干不相连的英文逗号分隔的字符串例如交大西直门天安门函数的返回值是一个列表它的元素是由每个逗号前后不含逗号的字符组成的元组
  • 下一篇: If we denote by N t the total number of the population at time t and by N t c a da that fraction of the total whose age is comprised at time t within the limits a and a + da it is evident that the ind

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2