Getting Started with Python: Loops & Dictionaries
I am studying Python with @skillcrush, in this article we cover loops and dictionaries
I am learning with Skillcrush. Please check them out and sign up if you're looking to break into tech!
Receive $250 off your course by using the link above. Use the coupon code: TWIXMIXY
NOTE: this discount is for Break Into Tech + Get Hired package exclusively.
It's the same program I am participating in!
🐍 Greetings travelers! We are studying Python with Skillcrush. In this article we cover loops and dictionaries.
🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜⬜ 50% DONE
I’ve wrapped up my Front End Developer portfolio at Skillcrush, read here:
I am now enrolled at UC Berkeley! 🏫 I will be taking their Full Stack MERN Coding Bootcamp through the remainder of the year.
You can subscribe without signing up for a substack account! Just select “None” when subscribing. All the content from my learning journey is free.
Loops
→ LOOPS
Keywords that let you repeat blocks of code until a condition is met.
→ FOR LOOPS
Used when you want to repeat a block of code a fixed number of times.
range()
function tells a for loop to run a specific number of times.
for i in range (0,6):
turtle.forward(100)
turtle.right(60)
→ WHILE LOOPS
Repeat a block of code until a condition is met.
Control structures in loops. In while loops, control structures like if or else can be used to tell the loop to stop running.
Iterate Through Numbers Challenge
I had a couple hiccups in how I wrote the code. I corrected two statements to get it functional. Not bad and continuing to challenge myself to write code, even when I’m not sure.
Build a To-Do List Feedback Challenge
For this one I’m not sure how I would have figured it out. In the while statement they wanted it to be while not
, which I don’t recall covering. Oh boy… and then how to wrap the list. My brain definitely hurts today, but not sure how I would have known to add this to the else
statement:
todo_list.append(new_item)
The biggest aspect of syntax tripping me up in the indentation still.
Turtle Module Challenge
Having some issues with my code that I’ve brought up to a TA. Basically something is wrong with the codebase for the starter I have. I built what I thought the lesson was and did pretty good with the assistance of BardAI. I was able to get the code to initialize, but when I select the shape I want, I get an error.
🟩🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜ 59% DONE
Dictionaries
→ DICTIONARY (IN PYTHON)
A data structure that holds groups of data values
→ KEYS
Unique elements in a dictionary that are mapped, or paired, to a data value.
→ VALUES
Data that corresponds to each key
Dictionary How To:
Write a dictionary
Get values from a dictionary
Add to a dictionary
Remove keys from a dictionary
Get a list of values and keys
Write a dictionary:
phone_book = {
“Matthew”: “773-202-7295”,
“Ava”: “964-1234-523”,
“Steven”: “608-752-6839”
}
Get values from a dictionary:
print(phone_book.get("Matthew"))
Add to a dictionary:
phone_book["Hannah"] = "888-923-5003"
Remove keys from a dictionary:
phone_book.pop("Stephen")
Get a list of values and keys:
for key,value in phone_book.items():
print(key + " => " + value)
Contact List Dictionary Challenge
len()
- checks the length of an element. Like how many contacts are stored.
I really didn’t get the instructions to this. Sometimes I feel like there are gaps between the lesson we review and the challenges. At least we have the solution code to review.
Loops in general for me are a struggle and something I’m still trying to grasp. So I’m letting this information wash over me and hoping some things will stick.
Language Translator Challenge
This one I felt more confident typing out and only had to change a couple syntax issues. This is definitely going to take some practice to get the hang of it.
Loops, just like in JavaScript continue to evade me at times. I know I need more practice and I will get there.
🟩🟩🟩🟩🟩🟩🟩🟩⬜⬜⬜⬜ 66% DONE
I’ve loved beginning to learn Python! Now that I have done work in both JavaScript and PHP I could see how once you learn one language it can be easier to adapt it to others. In the next article about Python we will cover classes, objects, file types, and more.
What did you think? Leave me a comment and share!