내멋대로 해라

icehan.egloos.com

포토로그 마이가든



[python] join tip&tech

S = 'Sometimes I feel like a motherless child'
가) 단어의 순서 바꾸기 : 'child motherless a like feel I Sometimes'

' '.join(S.split(' ')[::-1])

>>>S.split(' ') 
['Sometimes', 'I', 'feel', 'like', 'a', 'motherless', 'child']
>>>S.split(' ')[::-1]
['child', 'motherless', 'a', 'like', 'feel', 'I', 'Sometimes']
>>>' '.join(S.split(' ')[::-1])
'child motherless a like feel I Sometimes'

':'.join(t)
t는 리스트, :는 리스트를 연결할 문자

나) 문자의 순서 바꾸기 : 'dlihc sselrehtom a ekil leef I semitemoS'
''.join(list(S)[::-1])

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://icehan.egloos.com/tb/4870172 [도움말]

덧글

덧글 입력 영역