当前位置:网站首页><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])边栏推荐
- Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan
- The running kubernetes cluster wants to adjust the network segment address of pod
- 5V串口接3.3V单片机串口怎么搞?
- Technology sharing | packet capturing analysis TCP protocol
- Various uses of vim are very practical. I learned and summarized them in my work
- 总结了200道经典的机器学习面试题(附参考答案)
- EasyUI learn to organize notes
- 超标量处理器设计 姚永斌 第9章 指令执行 摘录
- [shortest circuit] acwing 1127 Sweet butter (heap optimized dijsktra or SPFA)
- How to connect 5V serial port to 3.3V MCU serial port?
猜你喜欢

Flet教程之 15 GridView 基础入门(教程含源码)

Reasons for the failure of web side automation test

《通信软件开发与应用》课程结业报告

Automated testing framework
![[extraction des caractéristiques de texture] extraction des caractéristiques de texture de l'image LBP basée sur le mode binaire local de Matlab [y compris le code source de Matlab 1931]](/img/65/bf1d0f82878a49041e8c2b3a84bc15.png)
[extraction des caractéristiques de texture] extraction des caractéristiques de texture de l'image LBP basée sur le mode binaire local de Matlab [y compris le code source de Matlab 1931]

Flet教程之 17 Card卡片组件 基础入门(教程含源码)
![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]

Talk about SOC startup (IX) adding a new board to uboot
![[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]](/img/65/bf1d0f82878a49041e8c2b3a84bc15.png)
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
![112. Network security penetration test - [privilege promotion article 10] - [Windows 2003 lpk.ddl hijacking rights lifting & MSF local rights lifting]](/img/b6/6dfe9be842204567096d1f4292e8e7.png)
112. Network security penetration test - [privilege promotion article 10] - [Windows 2003 lpk.ddl hijacking rights lifting & MSF local rights lifting]
随机推荐
Explore cloud database of cloud services together
Fleet tutorial 14 basic introduction to listtile (tutorial includes source code)
Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
Enclosed please find. Net Maui's latest learning resources
Blog moved to Zhihu
超标量处理器设计 姚永斌 第10章 指令提交 摘录
108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
《论文阅读》Neural Approaches to Conversational AI(1)
Test the foundation of development, and teach you to prepare for a fully functional web platform environment
112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
What development models did you know during the interview? Just read this one
Flet教程之 16 Tabs 选项卡控件 基础入门(教程含源码)
How much do you know about excel formula?
R語言使用magick包的image_mosaic函數和image_flatten函數把多張圖片堆疊在一起形成堆疊組合圖像(Stack layers on top of each other)
禁锢自己的因素,原来有这么多
Tsinghua Yaoban programmers, online marriage was scolded?
STM32 entry development write DS18B20 temperature sensor driver (read ambient temperature, support cascade)
Summed up 200 Classic machine learning interview questions (with reference answers)
Talk about SOC startup (VI) uboot startup process II