sentence = "I always lose at least one sock when I do laundry."
words = sentence.split()
words['I',
'always',
'lose',
'at',
'least',
'one',
'sock',
'when',
'I',
'do',
'laundry.']
['I',
'always',
'lose',
'at',
'least',
'one',
'sock',
'when',
'I',
'do',
'laundry.']
[[1, 2], ['buckle', 'My', 'Shoe'], 3, 4]
TypeError: 'str' object does not support item assignment
Detailed traceback:
File "<string>", line 1, in <module>
| item | location | price | |
|---|---|---|---|
| 0 | toothpaste | London Drugs | 3.99 |
| 1 | apples | Produce Store | 4.00 |
| 2 | bread | Bakery | 3.50 |
item1 = ['toothpaste', 'London Drugs', 3.99]
item2 = ['apples', 'Produce Store', 4.00]
item3 = ['bread', 'Bakery', 3.50]
column_names = ['item', 'location', 'price']
shopping_items = pd.DataFrame(data=[item1, item2, item3], columns=column_names)
shopping_items| item | location | price | |
|---|---|---|---|
| 0 | toothpaste | London Drugs | 3.99 |
| 1 | apples | Produce Store | 4.00 |
| 2 | bread | Bakery | 3.50 |
('I', 'lose', None, 'socks', 'when', 1, 'do', 'laundry.', False)
TypeError: 'tuple' object does not support item assignment
Detailed traceback:
File "<string>", line 1, in <module>
TypeError: 'set' object is not subscriptable
Detailed traceback:
File "<string>", line 1, in <module>
| Data Structure | preserves order | Mutable | Symbol | Can contain duplicates |
|---|---|---|---|---|
str |
✓ | ☓ | '' or "" |
✓ |
list |
✓ | ✓ | [] |
✓ |
tuple |
✓ | ☓ | () |
✓ |
set |
☓ | ✓ | {} |
☓ |