当前位置:网站首页><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])边栏推荐
- Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
- MySQL安装常见报错处理大全
- Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
- Matlab implementation of Huffman coding and decoding with GUI interface
- STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于SPI)
- Superscalar processor design yaoyongbin Chapter 10 instruction submission excerpt
- The Oracle message permission under the local Navicat connection liunx is insufficient
- [filter tracking] strapdown inertial navigation pure inertial navigation solution matlab implementation
- The function of adding @ before the path in C #
- 正在運行的Kubernetes集群想要調整Pod的網段地址
猜你喜欢

《通信软件开发与应用》课程结业报告
![[full stack plan - programming language C] basic introductory knowledge](/img/6d/555ac6b80b015e0cdfb7ef0a234f9d.png)
[full stack plan - programming language C] basic introductory knowledge

Flet tutorial 17 basic introduction to card components (tutorial includes source code)

禁锢自己的因素,原来有这么多

【全栈计划 —— 编程语言之C#】基础入门知识一文懂

Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist

STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于SPI)

How much do you know about excel formula?

核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?

HCIA复习整理
随机推荐
R language uses image of magick package_ Mosaic functions and images_ The flatten function stacks multiple pictures together to form a stack layers on top of each other
Summed up 200 Classic machine learning interview questions (with reference answers)
Talk about SOC startup (x) kernel startup pilot knowledge
SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
如何理解服装产业链及供应链
Easyui学习整理笔记
Nuclear boat (I): when "male mothers" come into reality, can the biotechnology revolution liberate women?
Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
[neural network] convolutional neural network CNN [including Matlab source code 1932]
正在運行的Kubernetes集群想要調整Pod的網段地址
Network protocol concept
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于SPI)
Suggestions on one-stop development of testing life
正在运行的Kubernetes集群想要调整Pod的网段地址
5V串口接3.3V单片机串口怎么搞?
Improve application security through nonce field of play integrity API