我想遍历一个字符列表
temp = ['h', 'e', 'l', 'l', 'o', '#', 'w', 'o', 'r', 'l', 'd']
{cd2>可以得到两个 我目前的方法是: 问题是这个打印出来了 等等。我怎么才能只打印出完整的有效字符串?在 编辑:我应该更具体地说明什么是“有效”字符串。只要字符串中的所有字符都是字母或数字,字符串就有效。我没有在我的检查条件中包含“isnumerical()”方法,因为它与问题没有特别的关系。在['h', 'e', 'l', 'l', 'o']
['e', 'l', 'l', 'o']
['l', 'l', 'o']
['l', 'o']
['o']
你可以这样做:
如果您只想要} 和{a2}轻松完成
hello
和world
,并且您的单词总是#
分开,那么可以通过使用^{如果您需要
^{pr2}$print
您需要的完整有效字符串List
具有返回元素位置的方法index
。可以使用切片来连接字符。在相关问题 更多 >
编程相关推荐