返回

python——求和并连接字符串的长度,使字符串的长度满足一个条件

发布时间:2022-03-24 18:52:01 288
# node.js

假设我有一个字符串列表,我想用它们发一条推文。例如:

# should be two tweets total 
this_list = ["Today is monday tomorrow is tuesday the next" ,"will be friday and after that", "saturday followed by sunday", "this month is march the next", "april after that may followed", "by june then july then we", "have august then", "september and october finishing", "the year with november and december" ]

我想要的输出与此类似(存储在当然列表中):

tweet 1:  'Today is monday tomorrow is tuesday the next will be friday and after that saturday followed by sunday this month is march the next april'
tweet 2:  'after that may followed by june then july then we have august then september and october finishing the year with november and december'

我曾尝试使用while循环来实现这一点,但我不确定循环是否正常工作。。。

out = [] # empty list
s = 0 # counter
tweet = "" # string to add too 
while s < 140:
    for x in this_list:
        tweet += x
        s += len(x)
    out.append(tweet)
print(len(out))


特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像