当前位置:网站首页><No. 8> 1816. Truncate sentences (simple)
<No. 8> 1816. Truncate sentences (simple)
2022-07-07 12:00:00 【Smoked Luoting purple Pavilion】
Catalog
Title Description :
The sentence It's a list of words , Words in the list are separated by a single space , And there are no leading or trailing spaces . Each word is made up of English letters in upper and lower case only ( No punctuation ).
for example ,"Hello World"、"HELLO" and "hello world hello world" It's all sentences .
Here is a sentence for you s And an integer k , Would you please s truncation , send truncation The following sentence contains only front k Word . return truncation s After the sentence .

Python Realization :
class Solution(object):
def truncateSentence(self, s, k):
"""
:type s: str
:type k: int
:rtype: str
"""
list_num = []
list_num = s.split(" ") # Split the original string by spaces
list_final = []
for i in range (k):
list_final.append(list_num[i])
return " ".join(list_final) # take list convert to str
In one line :
class Solution(object):
def truncateSentence(self, s, k):
"""
:type s: str
:type k: int
:rtype: str
"""
return " ".join(s.split(" ")[:k])边栏推荐
- MySQL安装常见报错处理大全
- 【滤波跟踪】捷联惯导纯惯导解算matlab实现
- SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
- Sonar:Cognitive Complexity认知复杂度
- [filter tracking] strapdown inertial navigation pure inertial navigation solution matlab implementation
- Suggestions on one-stop development of testing life
- In SQL, I want to set foreign keys. Why is this problem
- Talk about SOC startup (IX) adding a new board to uboot
- 本地navicat连接liunx下的oracle报权限不足
- [full stack plan - programming language C] basic introductory knowledge
猜你喜欢

Superscalar processor design yaoyongbin Chapter 9 instruction execution excerpt

【纹理特征提取】基于matlab局部二值模式LBP图像纹理特征提取【含Matlab源码 1931期】

powershell cs-UTF-16LE编码上线

The Oracle message permission under the local Navicat connection liunx is insufficient

【系统设计】指标监控和告警系统

请查收.NET MAUI 的最新学习资源

Camera calibration (2): summary of monocular camera calibration

Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift

sql里,我想设置外键,为什么出现这个问题

千人规模互联网公司研发效能成功之路
随机推荐
STM32 entry development uses IIC hardware timing to read and write AT24C08 (EEPROM)
When sink is consumed in mysql, the self incrementing primary key has been set in the database table. How to operate in Flink?
R language uses the quantile function to calculate the quantile of the score value (20%, 40%, 60%, 80%), uses the logical operator to encode the corresponding quantile interval (quantile) into the cla
Excel公式知多少?
Summed up 200 Classic machine learning interview questions (with reference answers)
《通信软件开发与应用》课程结业报告
MySQL安装常见报错处理大全
Present pod information to the container through environment variables
110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
In my limited software testing experience, a full-time summary of automation testing experience
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
相机标定(2): 单目相机标定总结
Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
千人規模互聯網公司研發效能成功之路
Talk about SOC startup (VII) uboot startup process III
竟然有一半的人不知道 for 与 foreach 的区别???
核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
Complete collection of common error handling in MySQL installation
Reasons for the failure of web side automation test