-1

I have this sentence: 'Johnny Johnny yes papa'. And I want to put the first element of this sentence (as a list) again at the end. This is my code:

sentence = 'Johnny Johnny yes papa'
if len(sentence)>0:
  sentence = sentence.split()
  sentence = sentence.extend(sentence[0])

But it returns me a none object. I tried this:

if len(sentence)>0:
  sentence = sentence.split()
  #sentence = sentence.extend(sentence[0])
  sentence = sentence.append(sentence[0])

And again, it returns none. Please, could you help me with this error? The intended list is: ['Johnny','Johnny','yes','papa','Johnny']

Alexis
  • 2,104
  • 2
  • 19
  • 40

1 Answers1

0

Because sentence.append(...) doesn't return anything. It applies on place. You just need to replace sentence = sentence.append(sentence[0]) with sentence.append(sentence[0]) line.

vszholobov
  • 2,133
  • 1
  • 8
  • 23