开发者

python reverse tokens in a string

开发者 https://www.devze.com 2023-01-28 18:30 出处:网络
I have the following string: apple.开发者_开发问答orange.red.green.yellow How can i reverse it to get the following:

I have the following string:

apple.开发者_开发问答orange.red.green.yellow

How can i reverse it to get the following:

yellow.green.red.orange.apple


I like this (more readable?) one:

>> s = "yellow.green.red.orange.apple"
>> '.'.join(reversed(s.split('.')))
'apple.orange.red.green.yellow'


'.'.join(s.split('.')[::-1])
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号