当前位置:网站首页><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])边栏推荐
- 禁锢自己的因素,原来有这么多
- MATLAB实现Huffman编码译码含GUI界面
- 正在運行的Kubernetes集群想要調整Pod的網段地址
- Use references
- How to connect 5V serial port to 3.3V MCU serial port?
- [data clustering] realize data clustering analysis based on multiverse optimization DBSCAN with matlab code
- Common locking table processing methods in Oracle
- UP Meta—Web3.0世界创新型元宇宙金融协议
- 5V串口接3.3V单片机串口怎么搞?
- powershell cs-UTF-16LE编码上线
猜你喜欢

竟然有一半的人不知道 for 与 foreach 的区别???

相机标定(2): 单目相机标定总结

MATLAB实现Huffman编码译码含GUI界面

Talk about SOC startup (VII) uboot startup process III
![108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]](/img/c0/8a7b52c46eadd27cf4784ab2f32002.png)
108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]

Automated testing framework
![108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]](/img/c0/8a7b52c46eadd27cf4784ab2f32002.png)
108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]

SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算

【最短路】Acwing1128信使:floyd最短路

STM32F1与STM32CubeIDE编程实例-315M超再生无线遥控模块驱动
随机推荐
SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
Time bomb inside the software: 0-day log4shell is just the tip of the iceberg
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
禁锢自己的因素,原来有这么多
Software design - "high cohesion and low coupling"
110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
Improve application security through nonce field of play integrity API
本地navicat连接liunx下的oracle报权限不足
Steps of redis installation and self startup configuration under CentOS system
Superscalar processor design yaoyongbin Chapter 10 instruction submission excerpt
C#中在路径前加@的作用
《通信软件开发与应用》课程结业报告
Rationaldmis2022 array workpiece measurement
Present pod information to the container through environment variables
Test the foundation of development, and teach you to prepare for a fully functional web platform environment
5V串口接3.3V单片机串口怎么搞?
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
R语言可视化分面图、假设检验、多变量分组t检验、可视化多变量分组分面箱图(faceting boxplot)并添加显著性水平、添加抖动数据点(jitter points)
Poor math students who once dropped out of school won the fields award this year