日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python语言逆序符号_python的逆序

發布時間:2025/3/11 python 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python语言逆序符号_python的逆序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面的代碼片段可以幫助您完成最后一個任務。

如果在字符串的開始或結尾之外的其他地方發現了特殊字符,則對于子集的恢復沒有特殊處理。在# Special chars which should be ignored for reverting

SPECIALCHARS = [' ', '.', ',']

def reverse( string_ ):

# Find occurence of 'special' chars. Stack position and char into a list.

specchar = [( i, ltr ) for i, ltr in enumerate( string_ ) if ltr in SPECIALCHARS]

if specchar:

# Remove all the special characters

newstring = ''.join( c for c in string_ if c not in SPECIALCHARS )

# Reverse the legal characters

newstring = newstring[::-1]

offset = 0

# Re-insert the removed special chars

for pos, char in specchar:

if pos + 1 + offset >= len( newstring ):

# Append at the end

newstring += char

else:

# Insert

newstring = newstring[:pos + offset] + char + newstring[pos + offset:]

offset += 1

return newstring

else: # No special char at all, so just revert

return string_[::-1]

print " '%s' =?= ' riatsilA, '" % ( reverse( " Alistair, " ) )

將導致以下輸出:' riatsilA, ' =?= ' riatsilA, '

只需返回忽略第一個和最后一個字符是一行代碼。

用這個來反轉“中間”:t[1:-1][::-1]

然后添加第一個和最后一個字符。在

^{pr2}$

編輯

好吧,現在我想我明白你想要什么了:-)newstr = ""

fullstr = ""

for char in mystr:

if char in SPECIALCHARS:

if len( newstr ): # Is already something to invert there?

#Ignore 1st and last char and revert the rest

newstr = newstr[0] + newstr[1:-1][::-1] + newstr[-1]

fullstr += newstr + char

else: # Special char found but nothing to revert so far

fullstr += char

newstr = ""

else: # No special char so just append

newstr += char

print "'%s'" % fullstr

總結

以上是生活随笔為你收集整理的python语言逆序符号_python的逆序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。