当前位置:网站首页>The length of the last word of the string
The length of the last word of the string
2022-04-23 15:40:00 【Ye Ningxia Xin】
One 、 Calculate the length of the last word in the string
Title Description : Calculate the length of the last word in the string , Words are separated by spaces , String length is less than 5000.( notes : The end of the string does not end with a space )
Input description :
The input line , Represents the string to be evaluated , Non empty , The length is less than 5000.
Output description :
Output an integer , Represents the length of the last word of the input string .
Title source : Cattle from ( Huawei machine test )
Their thinking :
1. Get the input string , use input()
2. use if The function judges that the length of the string is less than and not empty
3. use strip(’ ') Remove the spaces that may be entered on the left and right sides
4. Use string to list function split( Specify split character ) Split the string into a list with spaces
5. Get the length of the last element of the list , Starting from the first character, the subscript is 0, In turn , Start with the last character , Subscript to be -1, Decrease in turn ,-2,-3....
words = input()
if len(words) <= 5000 and words is not None:
words = words.strip(' ')
word_list = words.split(' ')
print(len(word_list[-1]))
Two 、python strip() Methods use
python strip() Methods use _liff_lee The blog of -CSDN Blog _strip Method
3、 ... and 、split() Function introduction
split() Function introduction _ Rookie's Road -- Oh, my blog -CSDN Blog _split function
版权声明
本文为[Ye Ningxia Xin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231534071722.html
边栏推荐
- 为啥禁用外键约束
- 一刷313-剑指 Offer 06. 从尾到头打印链表(e)
- 激活函数的优缺点和选择
- Why disable foreign key constraints
- Upgrade MySQL 5.1 to 5.67
- Explanation of redis database (III) redis data type
- G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
- 字节面试 transformer相关问题 整理复盘
- 服务器中毒了怎么办?服务器怎么防止病毒入侵?
- PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
猜你喜欢
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
服务器中毒了怎么办?服务器怎么防止病毒入侵?
Redis master-slave replication process
Why disable foreign key constraints
Codejock Suite Pro v20. three
KNN, kmeans and GMM
mysql乐观锁解决并发冲突
Mysql database explanation (IX)
群体智能自主作业智慧农场项目启动及实施方案论证会议
网站压测工具Apache-ab,webbench,Apache-Jemeter
随机推荐
2022年中国数字科技专题分析
Why disable foreign key constraints
fatal error: torch/extension.h: No such file or directory
Rsync + inotify remote synchronization
Upgrade MySQL 5.1 to 5.68
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
控制结构(二)
Upgrade MySQL 5.1 to 5.611
What if the server is poisoned? How does the server prevent virus intrusion?
Go语言条件,循环,函数
Configuration of multi spanning tree MSTP
PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
Mysql database explanation (IX)
KNN, kmeans and GMM
Codejock Suite Pro v20.3.0
Connect PHP to MySQL via PDO ODBC
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
大型互联网为什么禁止ip直连
Openstack theoretical knowledge
群体智能自主作业智慧农场项目启动及实施方案论证会议