Welcome back to {Kids: Code}, the free weekly coding newsletter! As we close out May and look forward to the summer, we’re gonna take some time this issue to review a neat tool for sorting information with Python. Speaking of sorting, we’re also going to share a great list of inspiring women from the history of STEM as put together by Stemettes!
As always, feel free to reach out to us or check us out on Twitter!
Does this tutorial look familiar? That’s because we’ve actually featured this in Issue #7! We wanted to take a moment to review this content as well as remind you of the archive of old editions of our newsletter that you can check out here.
Let's say you have an Array (or List) of animals, and you want to print them in alphabetical order... but they're not in that order.
animals = ["cat", "dog", "bird", "rabbit"]
for animal in animals:
print(animal)
# Prints:
# cat
# dog
# bird
# rabbit
Putting them into order, in programming, is called sorting. There are many different types of sorting (some more complicated than others), but for the sake of this example we'll go ahead and show how to sort them in alphabetical order.
Python makes this a one line trick - we just have to call sort() on our Array.
animals = ["cat", "dog", "bird", "rabbit"]
# Sort in alphabetical order!
animals.sort()
for animal in animals:
print(animal)
# Prints:
# bird
# cat
# dog
# rabbit
What if we wanted to sort them in reverse alphabetical order? In this case, we can pass a special bit of code to .sort(). We call this an argument, which in this case is reverse:
animals = ["cat", "dog", "bird", "rabbit"]
# Sort in reverse alphabetical order
animals.sort(reverse=True)
for animal in animals:
print(animal)
# Prints:
# rabbit
# dog
# cat
# bird
Sorting is, thankfully, a pretty universal concept for programming - you'll find it in just about every language, from Scratch to Python to Swift and more. It’s a handy tool when dealing with a large list of items and can be experimented with in many different ways. Why not try coming up with your own list and sorting it in your favorite programming language?
Stemettes is an organization based out of the United Kingdom that encourages young women to get into STEM related fields like programming and engineering, and their work has been highly important in promoting gender diversity. You can follow them on social media like Instagram where recently they uploaded a great list, from A to Z, of women who were legendary engineers, from Alice Perry (the first woman in the U.K. to graduate with a degree in engineering) to Victoria Drummond (the first woman to be a marine engineer in the U.K.)
As you might be able to tell, because Stemettes is a U.K.-based organization, a lot of these examples are going to be based in the U.K., but there is a lot of excitement in finding inspiring women in history who helped to push the boundaries of STEM learning all around the world. We can’t wait to see who else you end up finding!
It’s been a few weeks since we shared some news from Humble Bundle, hasn’t it? Fortunately, there’s still some time left on some great deals that also go to great charities.
The first one is the Learn You More Python book bundle from No Starch Press that includes $411 worth of materials for only $18! These books explore all corners of what Python offers including the very basics of the programming language, ways to make your code clean and neat, and even ways to build your own games and use Python in a game of Minecraft.
Another Python bundle, though a less beginner friendly one, is the Python Development bundle from Pluralsight that is perfect for anyone who is ready to take on some of the more complex challenges of programming. At $20 for all 20 books, this bundle offers a great next step for anyone who looked at the Learn You More Python bundle and thought, “I already know all of this stuff!”
Any purchases of these bundles will have a portion go to charities such as Girls Who Code, Code.org, the Python Software Foundation, and more. Be sure to check these out!
This Week’s Vocabulary Word
Sorting
When an algorithm puts a list (called an Array) into a specific order. A list can be sorted in many different ways like alphabetically or by number of letters.