【发布时间】:2019-10-18 06:51:24
【问题描述】:
问题:
给定一个字符串,其中字母 h 至少出现两次。 从该字符串中删除第一次和最后一次出现 字母 h,以及它们之间的所有字符。
如何找到 h 的第一次和最后一次出现?以及如何删除它们以及它们之间的字符?
#initialize the index of the input string
index_count =0
#create a list to have indexes of 'h's
h_indexes = []
#accept input strings
origin_s = input("input:")
#search 'h' and save the index of each 'h' (and save indexes of searched 'h's into h_indexes
for i in origin_s:
first_h_index =
last_h_index =
#print the output string
print("Output:"+origin_s[ : ]+origin_s[ :])
【问题讨论】:
-
题目和题目的内容不太一样
-
欢迎来到 SO。请花时间阅读How to Ask 以及该页面上的其他链接。
-
这个问题绝对是重复的;您应该将任何会话的前 5 分钟(至少)花在 SO 上,试图找出问题是否已经被问过。这不仅让您有机会在与“已被询问的内容”进行比较时收集 URL,还可以让您更好地了解如何以清晰和独特的方式提出问题,以及减少您的可重现示例到其最基本的部分。
标签: python string substring slice find-occurrences