This is going to be boring to non-computer geeks. Actually, I’ve known many folks, even in the computer industry, who dislike data structures. Back in my college days, my fellow students often called the class about it “Data Struggles”. I, however, fell in love. After taking that class, I knew that databases would be one of my favorite things. After that, most of my young career involved database design or data mining of one kind or another. I’m not talking about the file storage part today, though, because I haven’t gotten that far yet in the Python tutorial I’m learning from. Here, you get to watch me learn how the code manipulates data within a program’s short-term memory.
Yesterday, I learned and played around with how data is handled within Arrays (Lists) in Python. Again, I was applying a tutorial based on Python 2 to the Python 3 interpreter available in Windows SmartShell, so I had to adapt some code examples along the way. Also, the tutorial described some things poorly, so I had to experiment a little and sometimes chat on the side with Google’s long language model AI, Gemini, for better explanations.
Still, I find it annoying that my Python 3 interpreter doesn’t even try to be backward compatible to Python 2 code. I guess my generation of programmers is spoiled that way.
I’ll share with you now the fun I had in one of my favorite playgrounds. I actually had forgotten how much fun I used to have as a software developer. As you read, just imagine the sound of my constant giggling…
>>> x=[]
>>> x.append(1)
>>> x.append(2)
>>> x.append(3)
>>> x.append(4)
>>> x.append(5)
>>> x
[1, 2, 3, 4, 5]
>>> x.insert(0, 'in front')
>>> x
['in front', 1, 2, 3, 4, 5]
>>> x.insert(len(x), 'after')
>>> x
['in front', 1, 2, 3, 4, 5, 'after']
>>> bob=x.insert(4,'remove me')
>>> bob
>>> print(bob)
None
>>> x
['in front', 1, 2, 3, 'remove me', 4, 5, 'after']
>>> bob=x.pop(4)
>>> bob
'remove me'
>>> x
['in front', 1, 2, 3, 4, 5, 'after']
>>> harald=x.index(3)
>>> harald
3
>>> print(x.sort())
Traceback (most recent call last):
File "<python-input-98>", line 1, in <module>
print(x.sort())
~~~~~~^^
TypeError: '<' not supported between instances of 'int' and 'str'
>>> x.sort
<built-in method sort of list object at 0x000001CC3C080500>
>>> x
['in front', 1, 2, 3, 4, 5, 'after']
>>> x.sort()
Traceback (most recent call last):
File "<python-input-101>", line 1, in <module>
x.sort()
~~~~~~^^
TypeError: '<' not supported between instances of 'int' and 'str'
>>> x.sort
<built-in method sort of list object at 0x000001CC3C080500>
>>> x
['in front', 1, 2, 3, 4, 5, 'after']
>>> x=[3,5,4,6,5,4,6,5,4,9,1]
>>> x
[3, 5, 4, 6, 5, 4, 6, 5, 4, 9, 1]
>>> x.sort
<built-in method sort of list object at 0x000001CC3C316580>
>>> x.sort()
>>> x
[1, 3, 4, 4, 4, 5, 5, 5, 6, 6, 9]
>>> x.reverse()
>>> x
[9, 6, 6, 5, 5, 5, 4, 4, 4, 3, 1]
>>>