161k views
2 votes
Create a list words = ['is', 'NLP', 'fun', '?']. Use a series of assignment statements (e.g. words[1] = words[2]) and a temporary variable tmp to transform this list into the list ['NLP', 'is', 'fun', '!']. Now do the same transformation using tuple assignment.

1 Answer

2 votes

Answer:

words = ['is', 'NLP', 'fun', '?']

tmp = words[1]

words[1] = words[0]

words[0] = tmp

words[3] = '!'

print(words)

Step-by-step explanation:

- Create the list

- Assign the new values using tmp variable

- Print the result

Since tuples in Python are unchangeable, you cannot transform the list using tuple assignment.

User Vali
by
2.9k points