在输入的字符串中提取其中的姓名与职业信息,建立姓名职业字典并按键的顺序排列后输出,寻找其中职业字符串长度最长的条目(假设最长的只有一个)输出。 输入的字符串的格式形如(格式如下,逗号间隔,最后句号): Kim is a bookkeeper, Kate is an actress, Bartholomew is a barber. 输出: [('Bartholomew', 'barber'), ('Kate', 'actress'), ('Kim', 'bookkeeper')] ('Kim', 'bookkeeper')
1条回答 默认 最新
- shitou_12 2021-05-18 23:18关注
s = 'Kim is a bookkeeper, Kate is an actress, Bartholomew is a barber.' List = [] lens = [] for i in s.split('.')[0].split(', '): name = i.split(' ')[0] occupation = i.split(' ')[3] List.insert(0,(name,occupation)) lens.insert(0,len(occupation)) print(List) print(List[lens.index(max(lens))])
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条
- ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
- ¥15 perl MISA分析p3_in脚本出错
- ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
- ¥15 ubuntu虚拟机打包apk错误
- ¥199 rust编程架构设计的方案 有偿
- ¥15 回答4f系统的像差计算
- ¥15 java如何提取出pdf里的文字?