Python on the Train: Collections, Deque
Python on the Train: Collections, Deque
Good morning! I'm on the train.
It's a Tuesday - back to work. I had been planning on scrapping some of my extra problem solving work that I had planned to do. In favour of resting. And in favour of doing a bit more of the Python outside of hours.
But now I realise that I can't. All of my extra little plans:
- Listening to my call with my boss along with code
- Potentially re-listening to my other call
- Doing more sessions and potentially re-listening to those
- Listening to my podcast with Dave
- Turning that into notes and blog posts
- Buying a few A2 sheets and turning them into overviews of all of my problem solving skills
They need to be done somehow. But something else will have to go. Might pause LinkedIn for a bit or something. Hey we all know I can make these plans but they never work. The main thing is to rest. At least I have a long break over Christmas.
I want to try and get some things done before then
I made a wish on an eyelash
recap: Python containers
Python containers "store and organize data". Any object which stores data is called a container. Lists and dicts are built into Python.
You can import or custom-make other containers, though.
So we are going to be looking at specialized containers from the Python collections module.
Introduction to Specialized Containers
The collections module has classes. These contain new methods and utilities. They are similar to built-in collections. So unlike with built-in collections, we need to import the collections module.
I will be looking at both Advanced Containers and Container Wrappers in this module.
Deque
Deque containers are like lists but they are optimised for appending and popping to the front and to the back. They are great for working with data when you don't really have to access the contents in the middle very often.
Okay so this is so cool. As well as traditional appending and popping. We can also append to the front directly and pop from the front directly; here are the really cool methods:
- appendleft()
- popleft()
Both these two methods handle the front. Okay I need to do some of the actual code now although I feel as if I am about to fall asleep on the train.
Named Tuple
Had one look at this and they look HARD haha! Okay having looked over the code examples this doesn't seem too bad. Why do the code examples always help haha.
Okay, I need to play around with this a bit. Oh my God...
Comments
Post a Comment