Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Kenneth answers student questions while playing around with Python by doing a few practice projects and trying out some Code Fights.
-
0:00
[MUSIC]
-
0:05
I thought what we would do this week, we've done it before and
-
0:08
people seemed to like it, I wanna do it again.
-
0:11
Is just to build some learning code,
-
0:18
just kind of playing around with some code.
-
0:25
So I've got this one which is beginner python exercises.
-
0:31
I've got Karen's list of projects, which is basically any language you want.
-
0:37
And then there's also this site called CodeFights,
-
0:39
I don't know how many of you have seen CodeFights or not.
-
0:42
But it's pretty cool, they give you a challenge and
-
0:45
you have to go write the code for it in whatever language you want.
-
0:48
And then they tell you how well you're doing or not, which is cool.
-
0:55
So I'll leave that up to chat,
-
0:57
to pick like kind of which one of those they want for a minute or so.
-
1:00
If nobody comes in then I'll just pick one, and we'll do stuff.
-
1:06
But we'll talk about the code that we're gonna write.
-
1:08
We'll talk about just other Python things or
-
1:13
just programming things or whatever,
-
1:17
we'll talk about whatever you all want.
-
1:21
One thing that's really fun is today is my three year anniversary for
-
1:25
Treehouse, so that's kinda cool, I started three years ago today.
-
1:32
And also today is Andrew Chalkley's birthday, so
-
1:37
if you are a fan of Andrew wish him a happy birthday.
-
1:41
Mohammad, you want some PHP?
-
1:45
I'm trying to get Alina to do it,
-
1:47
there's a good chance I'm gonna get her to do it, probably next month.
-
1:54
Because I'm gonna be out for a week or two due to conferences.
-
1:59
So I'll try to get her to do it.
-
2:04
But PHP is a fun language, it's got some cool stuff.
-
2:07
I, unfortunately, haven't done it in a long time.
-
2:10
So I don't feel like it would be a great idea to have me doing PHP,
-
2:16
probably be a bad idea.
-
2:18
All right so, Let's
-
2:23
just try some practice projects over here.
-
2:27
Let's just see what we can find, that sounds fun.
-
2:33
So this one we have kind of a little
-
2:38
guide here showing, I guess, how hard this is.
-
2:43
These are all supposed to be basic beginner programs or
-
2:48
challenges, not super hard stuff.
-
2:53
And then Karen's Projects here, these are really, really spread out.
-
2:59
So we've got graphics stuff.
-
3:01
We've got threading stuff.
-
3:02
We got whatever.
-
3:06
So yeah, any of these that y'all would like to see?
-
3:12
Or we'll do some CodeFights.
-
3:16
This one's codefights.com.
-
3:18
This is github and this is practicepython.org.
-
3:26
Okay cool, so let's try one of these harder ones here,
-
3:34
just to see how hard the hard ones are.
-
3:39
Let's start off with a three.
-
3:45
Let's see. Let's try out the Reverse Word Order.
-
3:50
Okay, so write a program using functions
-
3:55
that ask the user for a long string containing multiple words.
-
3:59
Print back to the user the same string except with the words in backwards order.
-
4:04
So if we type in my name is Michelle, we get back Michelle is name my.
-
4:11
Okay, that's not too difficult of a thing, right?
-
4:16
So let's try this.
-
4:17
So we'll say, reverse_words.pi.
-
4:21
This actually sounds like something I would make all of you do as a code
-
4:26
challenge.
-
4:27
[LAUGH] So there should be many of you that could tell me how to do this one.
-
4:32
I'm gonna try and get these to where I can kind of see both things.
-
4:35
So let's say, reverse_words(string).
-
4:40
So the first thing we wanna do, we're taking in a bunch of strings,
-
4:43
or we're taking a string with a bunch of words in it,
-
4:46
we probably want to break it up, right?
-
4:49
So let's do words = string.split.
-
4:54
And that will break it up on the white space.
-
4:57
So, tabs, spaces, new lines, all kinds of stuff like that.
-
5:02
All right, and then we want to reverse that.
-
5:06
So, let's return, Space separated,
-
5:12
.join words in reverse order, that should do it.
-
5:18
So we'll say input("Give me a sentence: ").
-
5:29
And then we need to assign that to a variable.
-
5:34
Sentence.
-
5:36
And then let's say print(reverse_words(sentence)).
-
5:42
All right, so is there anything in here
-
5:47
that y'all find confusing or strange?
-
5:53
If there's something in these six lines,
-
5:56
that you're confused about, let me know, ask questions in chat.
-
6:02
But let's go ahead and run this, and we've got down here Give me a sentence, so
-
6:09
Hello to everyone in the live stream chat.
-
6:15
And we get back chat stream live the in everyone to Hello, so cool it worked.
-
6:22
Nice.
-
6:24
Let's actually go a step further.
-
6:27
Let's make it reverse the letters in the words and reverse the words.
-
6:33
So instead of, we'll effectively print the entire string backwards,
-
6:38
which that should be different.
-
6:41
Let me check to make sure this isn't gonna just do what I think it is.
-
6:47
We'll just print that.
-
6:49
All right, so say Hello to everyone in the live stream chat.
-
6:59
Yeah that would just do, okay so let's reverse the letters,
-
7:03
leave the words in order.
-
7:09
I'm going to change this too, so
-
7:10
reverse_word_order, Cuz that's the name that makes more sense.
-
7:17
Can I share the links?
-
7:18
I will do my best.
-
7:21
Chat is often weird about this for YouTube and stuff.
-
7:27
So let's see what we can do.
-
7:33
Let's try that and let's try this.
-
7:44
And lastly, I'll pop in this one.
-
7:53
Hey DarkDev, how are you doing?
-
7:57
All right, so yeah, we've got the reversing word or we print the words out
-
8:02
in the reverse order that they were put into the sentence.
-
8:05
Now let's print out the words in the order they were in the sentence but
-
8:09
each word reversed.
-
8:11
Not really harder to do but,
-
8:22
But still, it's a neat thing to do, it's fun.
-
8:26
So we wanna do words =
-
8:30
string.split, again, because we wanna break it up into a bunch of words, right?
-
8:36
And then I'm gonna do this as a list comp, so
-
8:41
let's return, space separated, .join.
-
8:46
And then word -1 through word in words.
-
8:52
Okay, so now, This
-
8:57
will be reverse_letter_order.
-
9:01
All right, and let's try this one again, so
-
9:05
we'll say again Hello to everyone in the live stream chat.
-
9:12
Sweet, so now you can see we've got the words in reverse order, but
-
9:16
then we have the words in the correct order but printed out backwards, right?
-
9:24
Abdul, I posted the links in the chat a minute or so ago.
-
9:29
And dimar, Python is completely free, yes,
-
9:32
you can go to python.org and download it, and enjoy.
-
9:37
All right cool. So
-
9:38
I think we've definitely solved that challenge, right?
-
9:43
That's not too bad.
-
9:47
Now these are definitely beginner challenges.
-
9:49
These are not ones that are like, you're going to spend a month
-
9:56
solving one of these things, so So that's cool.
-
10:00
What's the colon colon?
-
10:02
So Stern, you're talking about these two characters right here, right?
-
10:08
So that's a fun thing in Python.
-
10:10
In Python we have a thing called a slice, so
-
10:13
let me hop into the Python console here.
-
10:20
Okay, so I'm gonna make a string, all right?
-
10:23
So I'm gonna call this name and it's gonna be student, all right?
-
10:29
So if I want to get just one character out of there, I can use brackets,
-
10:35
the bracket notation and the index number of the letter, right?
-
10:41
So in this case I got s because s is
-
10:44
the zeroth index is the first thing in the string.
-
10:48
So if I want to get a couple of things out of here, then I can do the same thing.
-
10:57
Let's actually do the next one.
-
10:59
And then I can list the next one that I wanna get.
-
11:03
So I wanna get from one up to three, all right.
-
11:07
So if I do that I get T and E cuz this is one, this is two, and
-
11:11
we don't get three, we get up to three.
-
11:17
Hector, the link is in chat, just a little ways above you.
-
11:20
It's called code fights, codefights.com.
-
11:24
All right, so Stewn and everyone else who's wondering about the double colons.
-
11:31
So, that's how I get a sub string or a sub list of things, okay?
-
11:40
I can also do, like, let's say five I don't think that's quite right.
-
11:47
I can also list a step.
-
11:50
Okay, so that's t and u, so it got one,
-
11:56
two, three, four, it would have gotten five but it couldn't find it.
-
12:02
But it only took every other one.
-
12:03
So it did a step of one, and then a step of two took the next one, and
-
12:07
then stops, okay?
-
12:11
I can leave off anyone of those that I want and it will get,
-
12:15
if I leave up the first one I'll start at the very beginning.
-
12:19
If I leave out the last one, it goes to the very end.
-
12:22
If I leave off both of them and put in a step,
-
12:26
then I will get every other item, or every third item, or whatever.
-
12:32
I can put in negative steps though, and it will reverse, it will go backwards.
-
12:38
So it goes, in this case from the very back to the very front, and
-
12:42
in this case takes everyone, in this case we take every other one.
-
12:47
In this case we'll take every third one, that kind of thing.
-
12:51
So, that's what we're doing here is we're taking the entire list of words and
-
12:56
reversing that entire list.
-
12:59
Or in this case we're taking all the characters,
-
13:02
all the letters in the word, and reversing those.
-
13:05
So, yeah, that's what we're doing.
-
13:07
Thanks for asking me about that.
-
13:09
Darkdev, I am doing the lutem dare.
-
13:17
Yeah, my friend Owen and I are gonna do it.
-
13:19
[LAUGH] We're gonna use the language Rust,
-
13:24
and we're gonna use the GGEasy library.
-
13:29
So, we'll see how it goes.
-
13:36
I don't know that will go well, but we'll see how it goes.
-
13:41
We're not too worried about actually having something submitted.
-
13:44
We really only worried about building something and playing around with it.
-
13:48
So, if we get something built, that's cool.
-
13:51
If we get something submitted, that's amazing.
-
13:52
But if we don't, that's okay.
-
13:57
All right, Shamul, you wanna know about Tuples.
-
14:00
Okay, what do you wanna know about them?
-
14:04
Ask me questions about them and I will happily answer them.
-
14:08
While you're asking those, I am going to start the next one of these.
-
14:11
So I'm gonna call this passwords.pi so I'm gonna try this password generator.
-
14:18
And we're gonna see how we go here.
-
14:24
Okay, a couple of questions first.
-
14:27
Cigar asks, when should we stop with a particular programming language and
-
14:32
move forward to some other language?
-
14:33
Python is my first language.
-
14:34
You don't have to.
-
14:35
You never have to move on.
-
14:40
This isn't completely universal, the statement isn't completely true.
-
14:43
But every programming language is capable, right?
-
14:46
You can pretty much do anything you wanna do in pretty much any language, right.
-
14:52
You might have a really hard time making a high performance video game in PHP or
-
15:00
in I don't know, Manalua actually good for video games.
-
15:06
Anyway, right.
-
15:07
Some languages are better for some things than others.
-
15:10
If you're building desktop applications, Python's not particularly great,
-
15:13
it's okay, but it's not amazing.
-
15:15
So you don't ever have to move on so long as the work you're doing
-
15:20
works really well in the language that you like to use.
-
15:25
So just stick with it.
-
15:28
But it never hurts to know a couple of languages.
-
15:30
So that said, learn some other languages.
-
15:35
Marion asks, is migrating from PHP to Python difficult?
-
15:44
Yes and no?
-
15:45
I basically made that migration.
-
15:49
Python is a lot more strict about how you do certain things and
-
15:56
there's a lot less typing in Python than there is in PHP, like actual typing out
-
16:01
letters for a lot of things, not everything, but for a lot of things.
-
16:07
So some of those things are a little difficult, right?
-
16:11
Like having to obey those rules can be really hard for
-
16:14
some people when they go from PHP to Python, or any language to Python.
-
16:18
Python's very, you need to do these things in this way.
-
16:22
But it's not as hard as other languages, like say, Rust or Haskell, or whatever.
-
16:27
Anyway, so the migration's not the easiest thing but it's not super hard.
-
16:34
So Muhammad you want to know where it can be helpful, where what can be helpful?
-
16:40
I'm gonna scroll up a bit through the chat and see if I see.
-
16:49
Yeah, you said you want to know where that.
-
16:52
I want to know that where it can be helpful.
-
16:54
Can you tell me what the thing is that you wanna know where it's helpful?
-
16:59
And then Dimer has asked, PHP or C#, is it better?
-
17:03
It's really gonna depend on what you're doing.
-
17:08
Yeah, just depends on what you're doing.
-
17:10
Ryan, what are classes in Python, can I show an example?
-
17:15
I sure can.
-
17:17
And DarkDev, as far as the theme, you don't have to follow the theme.
-
17:22
The theme is just there to prevent the empty page syndrome.
-
17:25
I'm sure you've all experienced this, right?
-
17:28
You have to write a story for class or something or you have to write a program,
-
17:33
or you have to do whatever and you're presented with this page right here and
-
17:38
you are just like I don't know what to put into that page, right.
-
17:44
That can be really challenging.
-
17:46
So to prevent that the lutem dare people made it to where they gave you a theme.
-
17:51
And you can follow the theme if you want, you don't have to follow the theme but
-
17:54
the theme helps you to prevent that empty page thing because
-
17:58
okay I gotta build something that has to do with forest, okay great.
-
18:02
Okay, so, now if I do the question about python we've heard Ryan
-
18:07
wants to know about classes.
-
18:10
I bet we can use a class for this password generator.
-
18:12
And Shmuel doesn't understand the difference between dictionaries,
-
18:16
and tuples.
-
18:18
Okay, so we might be able to use both of those too.
-
18:22
So let's see what the problem is first.
-
18:26
Write a password generator in Python.
-
18:29
Be creative with how you generate passwords.
-
18:30
Strong passwords have a mix of lowercase letters, uppercase letters, number and
-
18:34
symbols.
-
18:35
The passwords should be random,
-
18:37
generating a new password every time the user asks for a new password.
-
18:41
Include your run-time code in a main method.
-
18:44
That should be function not method.
-
18:47
Extra, ask the user how strong they want their password to be.
-
18:50
For weak passwords pick a word or two from a list.
-
18:53
All right, cool.
-
18:54
So, lets do this.
-
18:56
Lets import string and let's also import random.
-
19:02
So, Python provides us with a lot of libraries, right?
-
19:06
And two of those libraries random and string are really useful, because they
-
19:12
contain modules that we can use to build other things or methods we can use rather.
-
19:18
Random let's us do random things.
-
19:21
Strings has a lot of stuff about like ASCII characters.
-
19:24
So, let's do password generator.
-
19:28
All right, so this is a class, guess what?
-
19:31
That's a class, that's it.
-
19:34
So, there's a class.
-
19:38
I've made a class.
-
19:39
But I probably need a bit more information about this, right?
-
19:44
So, let's have
-
19:49
a thing here where we do, let's say
-
19:55
strength, and we'll start with 16.
-
19:59
Okay, so self.strength = min().
-
20:16
How do I wanna do this?
-
20:19
I don't want them to be anything lower than 16.
-
20:26
Max, that's what I want, so 16 or strength, okay?
-
20:33
So this way, they have to give me something that is at least 16, right?
-
20:39
If they give us something above that, then that's cool, we'll use whatever that is.
-
20:44
If they don't give us something above that, we're gonna at least use strength.
-
20:49
And then, we want to do
-
20:54
self.password =
-
20:58
self.generatepassword.
-
21:04
We don't even need to get a pass on the strength,
-
21:06
that's gonna be stored on the instance.
-
21:09
And that's it, and then, we'll do def __str__ return self.password.
-
21:15
All right, so we have a class right now, and
-
21:19
its initialization method has an argument that comes in called strength,
-
21:23
which is always at least 16 due to this.
-
21:28
And then, we're gonna call this method called generate password,
-
21:31
which I haven't written yet.
-
21:33
And if we turn our PasswordGenerator instance into a string, it's gonna return
-
21:37
self.password whatever the string is that we've generated for the password.
-
21:43
So let's talk about how we generate this password.
-
21:48
Okay, so that has to take self because all instance methods take
-
21:53
the instance as the first argument, typically, that's called self.
-
21:58
All right, so I'm gonna use the strength to be how long the password is, okay?
-
22:06
So let's look at string,
-
22:11
where is string?
-
22:15
String, string, string, string, string, string, string.
-
22:17
It's down here somewhere, there it is, the module string.
-
22:20
All right, so you can see here, we have, very handy.
-
22:25
We have printable, we have digits,
-
22:30
we have ascii_letters, okay?
-
22:34
So we want those three things,
-
22:39
so let's just say, pool =
-
22:44
string.ascii_letters + string.
-
22:50
It wasn't not numbers?
-
22:51
digits + string.punctuation, okay, so
-
22:56
that's our pool of characters, right?
-
23:01
So we take our letters, our digits,
-
23:08
our punctuation and we're gonna cram those altogether into one big string.
-
23:12
And then, I wanna pull random things out of there.
-
23:15
So let's go look at the random module.
-
23:21
There's random, random has a really handy,
-
23:27
to me at least, function in it that is known as choices.
-
23:34
Cuz I don't necessary want shuffle, we'll look at shuffle later.
-
23:37
I don't necessarily want sample because sample is always unique, and
-
23:41
we do maybe want things to repeat.
-
23:43
So we're gonna use choices,
-
23:45
choices is going to pull out random choices up to a number that we specify.
-
23:51
So let's just do password
-
23:56
= random.choices(pool,
-
24:02
k=self.strength).
-
24:07
So that's going to pull out a random number of choices based on the strength
-
24:11
that we've passed in.
-
24:13
So we're basically making a string that is 16 or 32, or whatever characters long.
-
24:19
Then, I wanna take this a step further and I want to shuffle it, all right?
-
24:24
And so that will randomly shuffle them around, so cool?
-
24:30
So we do random.shuffle(password), so
-
24:33
it will randomly shuffle all those things around that it randomly picked out.
-
24:40
And then, is there anything else that I wanna do?
-
24:50
I don't think there is, to shuffle an immutable sequence and
-
24:54
return a new shuffled list,
-
25:03
We'll have to see what this does, I have a feeling this may error out.
-
25:07
Okay, so I think we're good enough for now, and
-
25:11
then, we're gonna do a return password.
-
25:15
So down here, let's do
-
25:21
a if __name__ == '__main__':
-
25:31
print(PasswordGenerator(input).("How strong
-
25:39
should your password be?") ) ).
-
25:45
All right, that's good enough for that, okay, so we're gonna run this.
-
25:48
How long should your password be?
-
25:50
Let's test this, I want something that's 10 characters long.
-
25:55
This should automatically give me back 16, right?
-
25:58
I should always get 16, I should never get anything below that.
-
26:06
That's right,
-
26:11
let's do this,
-
26:16
strength = d2ti,
-
26:22
there we go,
-
26:26
okay, so try
-
26:37
while True while strength
-
27:07
Yeah, that's what I want.
-
27:11
Isnumeric I'm not a big fan of this right here,
-
27:21
but it'll work for now.
-
27:23
else:
-
27:29
print(PasswordGenerator(int(strength))), all right,
-
27:37
let's try that one.
-
27:40
Should be 10, returned non-string list type.
-
27:56
There we go, all right, and let's see, 1, 2, 3, 4, 5, 6, 7, 8,
-
28:02
9, 10, 11, 12, 13, 14, 15, 16, 16, sweet.
-
28:08
So I got a password that is at least 16 characters long,
-
28:13
and it's a randomly generated password.
-
28:17
So that's cool, let's try this with something longer.
-
28:19
Let's try 32 as a much longer password.
-
28:23
So neat, so it gave me a random password, these would be fairly safe to use.
-
28:30
Hopefully, [LAUGH] no websites would reject it if you use those,
-
28:36
but yeah, so there's the password.
-
28:38
So here's an example using random, using string, and using a class.
-
28:45
I wanna look back through chat cuz I know I've seen some other questions come in.
-
28:49
And blah, blah, blah, blah, blah, okay, dictionary and
-
28:54
tuples, tuples, we'll go play with in a second, Shimul.
-
28:58
DarkDev, we're not gonna talk about the theme, we're not gonna worry about that.
-
29:03
David wants to know if I can program in Java, no?
-
29:09
I can read it, and I get a pretty good idea of what's going on in it.
-
29:12
I've been taking some of our Java content at Treehouse lately.
-
29:17
So push came to shove,
-
29:19
I could probably write just a little bit of Java, but no, Java's not my language.
-
29:25
It's a neat language, it's got some cool features.
-
29:28
But it's not one that I have any real confidence in myself in just yet.
-
29:35
Abdu says, they've just finished their first language, Python.
-
29:40
Congratulations on finishing a whole language.
-
29:42
And I wanna learn a framework to make a web application,
-
29:46
should I learn Bottle, Django, or Flask.
-
29:48
I would say, you probably wanna learn Django simply because it has all the bells
-
29:52
and whistles and bits and pieces that you typically need for
-
29:54
building a web application.
-
29:56
Bottle and Flask are gonna require you to bring those in yourself
-
30:01
Sometimes that's great, sometimes that's not.
-
30:06
So I think at the first step, you kinda wanna just have everything there with you
-
30:10
and you know that it's all gonna work.
-
30:12
Sagara asked, what is Python used the most for in companies?
-
30:17
It's used for a lot of things.
-
30:19
Facebook uses it for URL routing and service routing.
-
30:22
Instagram uses it for a good chunk of there stack or used to,
-
30:26
I'm pretty sure they still do.
-
30:28
YouTube uses it for a good chunk of their stack,
-
30:30
again used to pretty sure they still do.
-
30:33
It's used for data science a lot, so calculating where customers
-
30:37
are abandoning shopping carts, and all that kind of stuff.
-
30:42
It's used for a lot of things.
-
30:44
Nikos, this, This right here is
-
30:51
an application called Zeal, Z-E-A-L, and it is an offline documentation viewer.
-
30:57
If you're on Mac, there's one just like this that's really handy called Dash.
-
31:02
So yeah, check those out.
-
31:04
Chad, glad I could help you with OOP.
-
31:06
Blah, blah, blah, blah, [SOUND].
-
31:11
Sagara, if name equals main takes advantage of Python's name spaces.
-
31:17
So name here is the current namespace.
-
31:22
If I'm inside of a class or whatever, that class is now that namespace.
-
31:27
So in here this says, if the script is being run directly, then do this stuff.
-
31:33
If it's being imported somewhere else, don't do that.
-
31:36
Humanoid, how is Windows going?
-
31:38
Windows is fine.
-
31:40
I had kind of an annoying thing earlier, trying to get SDL set up on Windows,
-
31:45
but it turns out I was just doing it wrong.
-
31:49
It wasn't actually Windows fault, it was my fault for
-
31:52
not realizing I didn't have certain things installed and put in the right place.
-
31:57
So once I got those fixed, it all worked fine.
-
32:01
We'll take a look at some rust later, you all.
-
32:04
I'll do my best to explain a little bit of it, and we'll look at it.
-
32:08
Martin, what languages do I mainly know?
-
32:12
Full web like HTML, CSS, JavaScript, Python.
-
32:19
I can read and sorta kind of write, cuz I'm super rusty PHP.
-
32:22
I got a bit of Java, I got a bit of Rust,
-
32:25
I got a bit of Lua, I got bit of kind of whatever.
-
32:33
And Marion, yeah, Python's very friendly to machine learning.
-
32:38
So okay, cool.
-
32:39
I think we got that one.
-
32:39
I don't know that there's anything else here I wanna cover,
-
32:42
except maybe we'll do the birthday dictionaries here.
-
32:48
Just to help the person that was asking about
-
32:54
understanding tuples and dictionaries.
-
32:57
Humanoid, do I want a code fight?
-
33:01
Not at the moment, but maybe in a bit.
-
33:06
So let's get down here and let's do birth.
-
33:12
Birthdays.py, so the difference between tuples, which looks like this.
-
33:20
And dictionaries, which look like this.
-
33:24
Let's start by creating our birthdays here.
-
33:29
And we're gonna put in the birthdays of people's names, or
-
33:33
we're gonna have keys of people's names.
-
33:35
These are gonna be our birthdays.
-
33:37
So it looks like we're gonna have these three people.
-
33:42
So let's just, Paste those in there.
-
33:50
And the cool thing about dictionaries is,
-
33:56
you can have your keys as strings, right?
-
34:01
They can also be integers and they can also be tuples.
-
34:04
They can be anything that is non-mutable, that's immutable, so
-
34:07
it mean they can't be change.
-
34:13
Which means that you can do a lot of nice things with them
-
34:20
So let's pull out, let's actually find these people's birthdays.
-
34:26
So Albert Einstein, which I realized I just completely misspelled his name,
-
34:32
but Wikipedia's smart enough, they will find it for me.
-
34:37
Thanks Wikipedia for being smart.
-
34:38
So I'm actually gonna do these as dates.
-
34:45
So let's do datetime.date, and the year for this is 1879.
-
34:52
The month for that would be 3, and the day for that would be 14.
-
34:59
If I remember correctly, Python's date time does not zero index,
-
35:05
months, or days, unlike some people, JavaScript.
-
35:09
[LAUGH] So all right, let's also get Benjamin Franklin.
-
35:25
All right, so he was born 1706, 1, and 17.
-
35:33
And then lady Lovelace,
-
35:38
when were you born?
-
35:42
[LAUGH] Not Amazon, wow.
-
35:48
Lovelace, I'll see you around DarkDev, have a good day.
-
35:54
And yeah, Humanoid, [INAUDIBLE] are pretty much the best thing ever.
-
35:59
Okay, so Lady Lovelace was born
-
36:03
1815, 12, 10, cool.
-
36:11
So let's go back to this prompt.
-
36:13
So what where supposed to do is print out, I've got a bunch of birthdays.
-
36:20
Abdu, should you be a professional in Python to learn Jango?
-
36:23
No, you can learn Jango before you're a professional.
-
36:28
I don't know if there really is a, yeah, there's no requirement.
-
36:33
So just learn stuff when you wanna learn stuff.
-
36:38
Okay, so let's print, welcome to the birthday dictionary.
-
36:47
We know the birthdays of, and
-
36:52
then here we're going to do, for name in birthdays, print name.
-
36:59
So when you loop over a dictionary, when you do a for
-
37:02
loop on a dictionary, what you're actually looping over is the keys.
-
37:05
Because the keys are the primary part of a dictionary, they're the part that's the,
-
37:10
not to say most useful, but they're the most static part of a dictionary.
-
37:14
They're the part that Python does its best to store right upfront somewhere nice, and
-
37:18
handy easy to get to.
-
37:19
So when you loop over it, that's what you get.
-
37:23
So in this case we're gonna print out the names, and
-
37:25
then we're supposed to do an input here.
-
37:28
Let's do name equals.
-
37:31
And then inside here, whose birthday do you want to look up?
-
37:44
And then let's say, they're gonna do that name.
-
37:50
And then, we'll do print birthdays name, okay?
-
37:59
So let's go ahead and run this,
-
38:04
and I wanna look up Ada Lovelace's birthday.
-
38:12
And let's do a .trim on that.
-
38:21
Does trim not exist?
-
38:29
No, it's strip.
-
38:31
What am I doing?
-
38:35
All right, so that should print out that.
-
38:37
But I have a feeling that this is going to look a little weird.
-
38:40
So yeah, so that's not necessarily the format that I'm used to, right?
-
38:48
That's not necessarily the way I wanna read it.
-
38:52
So I'm an American, so I typically want to do month, day, year, which is weird.
-
38:59
But let's go ahead and do it that way.
-
39:03
STRF time, we wanna format this.
-
39:05
And how do we want to do this?
-
39:09
Let's go down here and
-
39:13
look at the list.
-
39:16
So I want the month first, so let's actually do this as the month's full name.
-
39:24
So %B, that's not a percent.
-
39:26
That's not a percent either.
-
39:34
Percent, capital B, and then the day of the month is %d.
-
39:41
And then the year is %y.
-
39:45
All right, let's try this again.
-
39:48
Ada Lovelace, December 10, 1815.
-
39:52
So cool, that's nice.
-
39:54
That's neat.
-
39:55
All right, so that's pretty simple.
-
39:57
I think we've pretty much exhausted these.
-
40:01
These basic challenges.
-
40:03
So we're gonna try something a little harder.
-
40:05
Humanoid, what music do I listen to?
-
40:08
The music in the stream is Chris Zabriskie,
-
40:10
he is a Treehouse employee and he makes pretty awesome music.
-
40:16
As for me personally, It's somewhat of a interesting mix maybe.
-
40:24
There's a lot of like, 90s, early 2000s
-
40:29
punk hard core, and rock.
-
40:35
And then like 1950s and 60s country, and
-
40:39
then just other random stuff as it comes up.
-
40:42
Zeeshon, what do I think of TensorFlow?
-
40:44
I haven't gotten to play with it.
-
40:46
But it seems pretty cool.
-
40:48
So I don't, I don't have any problems with it.
-
40:53
I think it's cool, but I haven't gotten too far through it.
-
40:58
Peter, this is not a django project.
-
41:00
We are just doing some different code challenges, and
-
41:02
we're just talking about programming.
-
41:05
So, today's kinda more of a chill
-
41:09
relaxed stream than before.
-
41:13
Abdou, can I explain super function?
-
41:16
Sure, I can explain super.
-
41:22
So, let's pretend that we have, Yeah, let's just do this.
-
41:31
Let's do a,
-
41:39
BadPasswordGenerator.
-
41:44
And this inherits from PasswordGenerator, okay?
-
41:50
So right now this class is fine, and this class just does all it's own stuff, right?
-
41:56
So, well not all of it's own stuff, sorry.
-
41:58
It does whatever PasswordGenerator does.
-
42:00
But I want to override some of this.
-
42:03
So I'm gonna take self, and I'm gonna take any args and kwargs that come in.
-
42:10
But I don't care about them, right?
-
42:13
What I'm gonna do is I'm gonna do super().__init__.
-
42:18
And strength is gonna be equal to,
-
42:26
Actually I'm not gonna pass anything in, okay?
-
42:30
So now we have the same password as we had before, okay?
-
42:34
But I'm ignoring any kwargs that come in,
-
42:36
I'm not listening to you on whatever you're gonna feed me.
-
42:39
You can say, I want this to be 82 characters.
-
42:42
I don't care, I'm ignoring that and I'm calling super and
-
42:46
I'm just letting it do whatever.
-
42:48
So then I'm gonna say self.strength
-
42:54
= 8 and self.password
-
42:59
= self.generate_password, okay?
-
43:08
So now down here instead of thatm let's do BadPasswordGenerator.
-
43:13
We're gonna run this, I want it to be 32 characters long,
-
43:16
no matter what I get an 8 one.
-
43:19
So the super calls the same function, or
-
43:24
same method usually, from the parent class.
-
43:27
So in this case, this calls init from here, it causes this init to be run.
-
43:35
And then we could go on and do whatever we want.
-
43:38
So super just goes to the super class and runs that method,
-
43:42
or runs the method that you specify.
-
43:45
All right there's no music in the stream, there should be.
-
43:52
It's just very, very quiet right now.
-
43:55
So, I don't know.
-
43:58
All right, let's try one of these code fights.
-
44:00
I'm not sure how the code fight goes against somebody.
-
44:06
Humanoid, if you want to tell me how to do that one.
-
44:09
But let's just try whatever the day's challenge is.
-
44:18
So what do we have?
-
44:19
We have algorithmic and we have database.
-
44:24
All right, let's just set for, I don't wanna deal with database stuff.
-
44:41
I don't know what I really wanna do.
-
44:43
Too many of these.
-
44:45
The longestConsecutive one's kinda neat but I don't wanna deal with binary stuff.
-
44:51
Let's look at the strings one.
-
44:54
Given an array of equal length strings, check if it's possible to rearrange
-
44:58
the strings in such a way that after the rearrangement
-
45:01
the strings at consecutive positions would differ by exactly one character.
-
45:07
For InputArray, "aba", "bbb", "bab", the output should be false.
-
45:13
Okay, for InputArray "ab", "bb", "aa", the output should be true.
-
45:17
Because the strings can be rearranged in the following way, "aa", "ab", "bb".
-
45:25
Okay, that, Seems all right.
-
45:35
So we get back a whole bunch of strings.
-
45:41
What's the, I'm just gonna look up distance.
-
45:48
I don't think that's gonna give me what I want, but
-
45:53
it's like the Levenshtein distance or something like that.
-
46:01
Yeah, that not gonna get me what I want.
-
46:05
Levenstein, I know I misspell that but Dr.
-
46:09
Google know what I want, yeah.
-
46:13
Okay, so there's a package that does it, that's cool.
-
46:15
I don't really want a package cuz I can't install one.
-
46:19
I just want the actual thing.
-
46:24
You did it in C, you didn't even do it in python.
-
46:35
Wait just a second and let me look at the package.
-
46:38
So we have that external package, yeah.
-
46:48
We don't have any entry points, okay.
-
46:54
So if I remember correctly this is the thing that we want.
-
46:57
Okay, we want the Levenshtein-Distance of two strings.
-
47:00
All right, so let's try building this real quick first, and
-
47:04
then we'll see what we can get here.
-
47:07
Option that's it, there we go, how do you spell that, S-H.
-
47:14
Levenshtein.py, all right.
-
47:18
So this is Python 2.
-
47:25
We're gonna have to change this so that it's Python 3.
-
47:31
But, that's okay.
-
47:33
Okay, so we don't wanna print.
-
47:41
We don't wanna print like that and we don't wanna print like that.
-
47:46
And this should be input and input.
-
47:54
And that should be like that.
-
48:03
Okay, so let's try this out.
-
48:05
So if I do aa and ab,
-
48:09
'range' object does not support item assignment.
-
48:13
That's true.
-
48:14
It doesn't.
-
48:21
Where did we try to do item assignment?
-
48:24
Class range does not define that, okay.
-
48:26
So matrix, at this point, This is
-
48:31
why you don't use really bad little variable names, kids.
-
48:37
Okay, I'm not even gonna worry about that.
-
48:42
So we get the length of each of the two strings, okay?
-
48:47
And then we do range, length of the first 1 + 1.
-
48:56
Okay, * link to the second one + 1.
-
49:01
And then for each thing that's in range,
-
49:05
link of the second one + 1, we do matrix,
-
49:10
whatever that thing is = range.
-
49:17
Where we're at plus the length of the first 1 + 1.
-
49:24
Okay, so then for zz and range length of the second one,
-
49:29
for sz and range length of the first one,
-
49:33
if, Okay, if the first string plus the place
-
49:39
that we're on is equal to the second string plus the place that where at,
-
49:47
Then matrix[zz +1], I see.
-
49:55
I need to turn this into a list.
-
50:25
Okay, so we're doing the min out of each of those, and
-
50:29
then down here, we need the same thing.
-
50:34
So that equals this list here.
-
50:40
And this list here, And this list here.
-
51:03
Okay, let's try this one again, aa,
-
51:08
ab, and our distance is four, okay.
-
51:14
So what about aa, bb?
-
51:18
Our distance is four.
-
51:19
Maybe, this isn't gonna do what I want it to do.
-
51:25
[LAUGH] What was that other example that they had?
-
51:28
aba and bbb,
-
51:38
Yeah, cuz that's got more than one character.
-
51:41
So that's six, so maybe, if the distance
-
51:56
Okay, so aa and bb, that was also a four.
-
52:03
All right, so somebody asked if the C programming language
-
52:08
able to create an online game like an MMORPG or
-
52:12
edit someone else's online game, could you create an MMORPG?
-
52:18
Yes.
-
52:21
Could you edit someone else's MMORPG?
-
52:23
Probably not.
-
52:28
Okay, Humanoid, I'm gonna not worry about this one.
-
52:32
How do I see the challenge?
-
52:35
This one, I'm guessing.
-
52:41
Okay, get ready.
-
52:43
You assume I know what I'm doing, CodeFights, Look at all your stars, man.
-
52:49
You got four stars.
-
52:52
All right, now I'm not promising anything,
-
52:53
I'm not promising I'm gonna do better than you.
-
52:55
I'm not promising I'm gonna do worse than you, either.
-
52:58
Okay, given an array of integers, find the pair of adjacent integers
-
53:03
based on elements that has the largest product and return that product.
-
53:09
So, for input array 3, 6, -2, -5, 7, 3, the output should be 21.
-
53:16
7 and 3 produce the largest product, okay?
-
53:24
Okay.
-
53:25
So let's start that.
-
53:29
Come on, you all, this is not how you format code.
-
53:33
Okay so,
-
53:36
[MUSIC]
-
53:40
First equals that and that.
-
53:41
[MUSIC]
-
53:44
Was this your code?
-
53:46
Or is this.
-
53:50
No, this is just some code that they gave.
-
53:52
Okay.
-
53:56
Best equals none.
-
53:59
Yeah, best equals none for x, y and z.
-
54:06
Input array.
-
54:07
Input array.
-
54:08
1: if X times Y
-
54:13
greater than thest.
-
54:19
Actually, if best is none or,
-
54:28
So Y equals that, best equals X times Y.
-
54:36
Return Best.
-
54:51
Expected output got 18, expected 21.
-
55:08
You think I can only change one line?
-
55:12
Let me reset the code.
-
55:16
Okay so they're doing best= InputArray[0] * InputArray[1], cur = best.
-
55:23
For I in range (1 to the len(InputArray)-1).
-
55:28
Cur= InputArray[i] * InputArray[i + 1].
-
55:32
If best < cur, cur = best.
-
55:38
Return best, and running that one, Fails, it fails all of the tests, right?
-
55:46
Two out of eight.
-
55:54
See, I don't like the way they're doing this.
-
56:00
Okay, I'm probably not gonna beat you, as I'm having to code on the spot on camera.
-
56:06
So, [LAUGH], okay.
-
56:22
Yeah, this is a silly way of doing it like this is fine, right?
-
56:24
Like that's fine whatever, do that.
-
56:31
But for XY in zip,
-
56:35
input array input array
-
56:40
1:, Right?
-
56:45
Because that way you're never comparing two numbers to themselves.
-
56:51
So, cur is equal to x times y, if this is less than that, okay.
-
56:58
Run your sample tests.
-
57:01
Number of lines changed in the sample code.
-
57:05
I'm gonna look over here at the rules.
-
57:08
There's one bug.
-
57:11
I'm just looking for a bug, I didn't know I was just looking for a bug.
-
57:19
All right, best is equal to that times that.
-
57:26
I wanna arrange that,
-
57:39
This should be best equals cur.
-
57:46
Yeah.
-
57:49
No, Humanoid it is cool, it's not what I was expecting, right?
-
57:54
So, yeah.
-
57:56
[LAUGHING] All right, now I get it.
-
58:01
Now I see the rules.
-
58:02
Okay, cool.
-
58:04
[LAUGHING] Let's go over the next one.
-
58:11
Okay.
-
58:11
Given an array of integers, find a product of its elements.,
-
58:16
So I've got an array full of numbers, get back to the total products.
-
58:22
Rules on this one.
-
58:23
Recovery task.
-
58:24
The highlighted area of the code is missing, understand and recover it.
-
58:28
Note that multiple lines of code might be missing.
-
58:30
Okay, so I'm gonna get an array, and
-
58:34
then I need to return the total product of that array.
-
58:41
Okay?
-
58:43
Should be easy enough.
-
58:45
Can I start?
-
58:48
Do I just wait for the timer to run out?
-
58:56
I guess I got to wait for the time to run out.
-
58:57
All right, let's see what's going on in chat.
-
59:01
And if anybody else wants to challenge me I'll probably have time to do another one
-
59:06
after this, so feel free to go sign up on Code Fights and fight me on something.
-
59:12
We have 17-year-old from Egypt.
-
59:13
That's cool.
-
59:14
How you doing?
-
59:15
You've got seals in Visual Basic.
-
59:16
That's a good starting language.
-
59:18
And Peter, or Petter?
-
59:23
Tell me which one of those it is.
-
59:25
I'm glad that you're enjoying the series.
-
59:26
That's cool.
-
59:28
All right, so let's start.
-
59:30
What is up, why can't I?
-
59:35
I'm gonna refresh.
-
59:37
And now watch I'm gonna have to do the first fight again.
-
59:42
[BLANK_AUD [SOUND] Look what you've done, Humanoid.
-
59:50
Look at this.
-
59:51
Now we're all just watching a spinner.
-
59:54
Humanoid [LAUGH].
-
59:58
No, it's not your fault at all, it's CodeFights being weird, I guess.
-
1:00:03
Privacy Badger, yeah, you can block user voice, I don't care about user voice.
-
1:00:11
I have no code friends online, no.
-
1:00:15
Okay, so it's figured out that we're on Round 2.
-
1:00:19
All right, cool, hey, there we go.
-
1:00:22
Okay,
-
1:00:37
Seriously?
-
1:00:45
No, I know what this is supposed to be, this is supposed to be InputArray[0].
-
1:00:52
Yeah, CodeFights is really slow, double t the segment, so it's Petter and not Peter.
-
1:01:00
Okay, well Petter, I'm happy to have you here.
-
1:01:05
What can you learn when you're 17 years old?
-
1:01:07
You can learn anything you want.
-
1:01:09
I mean, yeah go learn Python, go learn PHP, go learn JavaScript,
-
1:01:14
go learn C#, learn whatever.
-
1:01:20
How are ya'll doing?
-
1:01:21
[LAUGH] I guess we're gonna just wait here.
-
1:01:27
Can I list the extension that I'm using in chrome, which one?
-
1:01:31
I have a lot of extensions in chrome.
-
1:01:34
If you can tell me which one you want to know.
-
1:01:39
Yeah, you're not a beginner, you've been doing VB for years.
-
1:01:43
So yeah, go build pretty much anything you want, right?
-
1:01:49
Use VB to build apps or whatever.
-
1:01:55
Sweet, so I passed that one.
-
1:01:56
All right, let's go to the next one.
-
1:01:58
All right,
-
1:01:59
the algorithm should return the smallest non-negative integer of N digit's length.
-
1:02:04
So, if we want an integer that is three digits long,
-
1:02:09
then we return the smallest one that is at least that.
-
1:02:13
Okay, I don't care about solutions.
-
1:02:17
CodeWriting, so I'm just writing straight code in this one.
-
1:02:20
Okay, Let's start coding,
-
1:02:26
all right, so what do we want here?
-
1:02:31
We want length =
-
1:02:42
length = n?
-
1:02:46
I don't even need that, okay.
-
1:02:49
So what I want is the smallest number,
-
1:02:55
so let's see, base =,
-
1:03:05
10 to the power of n.
-
1:03:12
That's not right, cuz if I do that and
-
1:03:16
I get 10 to the power of 1, I get 10.
-
1:03:26
And I don't want 1, All right, let's just do this.
-
1:03:37
Return min, (map[int.
-
1:03:48
Filter [lambda x len(x) == n])),
-
1:03:57
I'm going to break this up a little bit.
-
1:03:59
Because y'all won't ever be able to read this,
-
1:04:05
and I won't remember what I was doing [LAUGH].
-
1:04:12
Okay, Okay,
-
1:04:19
so lamba [SOUND] and map(str,
-
1:04:23
[MUSIC]
-
1:04:35
Hold on I'm not thinking this through at all.
-
1:04:40
[MUSIC]
-
1:04:43
I'm thinking it's gonna feed me numbers, okay.
-
1:04:46
If n == 1, return 1, else: return 10 to the power of n.
-
1:04:53
[MUSIC]
-
1:05:05
My favorite Chrome extension.
-
1:05:07
[LAUGH] My favorite one is probably privacy badger, or
-
1:05:11
uBlock Origin, because it keeps me from having to see annoying things.
-
1:05:18
Also HTTPS everywhere, those are great, I use those a lot.
-
1:05:25
Peter you are just catching up that cool, yeah,
-
1:05:28
we've been doing this about six months now so there is quite a bit to watch,
-
1:05:32
hopefully Hopefully you will like all the stuff that you watch.
-
1:05:37
Zander any good sites to practice Lua?
-
1:05:39
So I don't know anything for practicing Lua specifically, but
-
1:05:42
there is this getup.com/karen/projects.
-
1:05:47
These are language agnostic challenges So
-
1:05:52
you can go and do them in any language that you wanna do.
-
1:05:56
So Java, LUA, Python, PHP,
-
1:05:58
whatever cuz you're just doing them on your own computer.
-
1:06:02
So you can kinda do whatever it is you wanna do but
-
1:06:05
it's a really good test there.
-
1:06:15
That should be n- 1.
-
1:06:42
All right, how did we do?
-
1:06:45
You beat me.
-
1:06:47
Well, good for you.
-
1:06:49
Good job.
-
1:06:50
Yeah, that was, those were good challenges.
-
1:06:54
Like I said, you're probably gonna beat me because I'm doing this live on camera.
-
1:06:58
And I didn't know what the challenges were of course.
-
1:07:02
So, but that's cool.
-
1:07:04
Code Fights is a really neat thing, I I need to play with it more and
-
1:07:11
I need to do more coding on this.
-
1:07:19
I am wondering if some of this time should be stripped because of just how
-
1:07:24
freakishly long it took to submit those things, right like
-
1:07:29
Though some of those things took like minutes to submit.
-
1:07:33
Maybe that's because I'm streaming, that could very much be part of it because I'm
-
1:07:37
pushing out, you know, video to everybody.
-
1:07:40
But, yeah that's pretty hard core.
-
1:07:45
But yeah great job Humanoid.
-
1:07:47
So Everybody give Humanoid some congratulations, some thumbs up.
-
1:07:52
So, Sca Kraft, cuz I can't pronounce your Arabic name there, sorry.
-
1:07:58
You said you want to make 3D games.
-
1:08:00
You're probably gonna wanna learn something other than VB To make 3D games.
-
1:08:07
Those two words sound a lot alike.
-
1:08:09
Java is an okay choice, but you're probably best off really with c++ or c#.
-
1:08:16
If you do c++ then you can build stuff with Unreal Engine,
-
1:08:22
c# you can build stuff with You can build stuff with Unity.
-
1:08:29
Those are probably your best two choices for
-
1:08:34
doing 3-D things.
-
1:08:37
All right.
-
1:08:39
Do you all want to look at rust?
-
1:08:40
You want me to show you.
-
1:08:43
some rust that I've done,
-
1:08:44
by playing totally from tutorials, totally from other stuff.
-
1:08:48
But, I can show you some rust, because rust is kind of cool.
-
1:08:53
It's neat.
-
1:08:58
Marion, thanks, I'm glad that I look friendly for my age.
-
1:09:04
I won't tell you how old I am or am not.
-
1:09:08
But yeah I try to be friendly.
-
1:09:16
I'm glad that came through.
-
1:09:19
So rust is kind of cool because rust A, this is rust.
-
1:09:26
Let me make this a little bigger.
-
1:09:27
I know that you all have a harder time seeing it on
-
1:09:32
the screen because of it being smaller.
-
1:09:38
So let's go to 18 for that.
-
1:09:39
That should be big enough.
-
1:09:42
All right, cool.
-
1:09:44
So Rust is cool.
-
1:09:45
Rust is a langauge that looks a lot like,
-
1:09:48
it doesn't really look like Java but it kinda looks like Java.
-
1:09:53
it doesn't look like C, but it kinda looks like C.
-
1:09:57
And it doesn't look like Python, but it works a lot like Python.
-
1:10:00
A lot of it is very similar to me as a Python,
-
1:10:04
and having done Ruby in the past, very similar to that.
-
1:10:08
So you always have this main.rs file in your project,
-
1:10:12
and then inside that there's always this function called main.
-
1:10:17
Now Rust is a very functional programming language,
-
1:10:22
it's meant to do functional stuff.
-
1:10:26
And so yeah, you'll find a lot of functional
-
1:10:31
programming oriented stuff in Rust.
-
1:10:36
So this is FizzBuzz, so I'm sure you've all seen FizzBuzz at some point.
-
1:10:40
The idea is you take all the numbers from 1 to 100,
-
1:10:42
if the number can be divided by 3 you print out fizz,
-
1:10:46
if it can be divided by 5 you print out buzz, if you can divide it by both 3 and
-
1:10:52
5 you print out fizzbuzz, otherwise you just print out the number.
-
1:10:58
So this is a for loop, as you can tell by the use of the word for.
-
1:11:05
[LAUGH] And so this gives us, if I was doing this in Python it would be for
-
1:11:11
num in range(1, 101), right, that's what I'd write in Python.
-
1:11:17
So this is for num in range 1..101, very similar.
-
1:11:25
And so inside of there if the number divides by 3 and
-
1:11:28
the output of that is 0 then I check to see if it'll also divide by 5 and if so
-
1:11:32
print out fizzbuzz, otherwise I'm gonna print out fizz.
-
1:11:37
If it divides by 5 evenly we print out buzz, otherwise we print out the number.
-
1:11:41
Any time you see this exclamation mark like that that's a macro,
-
1:11:45
you're not exactly running a function but you're kinda sorta running a function.
-
1:11:53
This is an area I don't know yet so ignore me on a lot of this, but it's pretty cool.
-
1:11:59
This is pretty simple to read I think, and if we run it you'll see
-
1:12:04
that it's very fast, it runs very quickly so that's cool, that's fun.
-
1:12:10
Let's look at something a little bigger that I did with the help of a tutorial.
-
1:12:16
Because I don't know all of this
-
1:12:21
myself yet, so we'll find out.
-
1:12:27
tska-craft I cannot teach you C++ and Treehouse won't teach you C++, but
-
1:12:32
we will teach you C# and we can teach you Unity, so we have both of those.
-
1:12:37
And am I the person who appears in Treehouse advertisements,
-
1:12:43
I'm probably in some of them but
-
1:12:46
I'm not in all of them I don't think, [LAUGH] I don't know.
-
1:12:52
Ryan, what is the best language for framework for back-end webdev,
-
1:12:55
give you an answer straight up.
-
1:12:58
I can't give you an answer straight up because there's no answer to that,
-
1:13:04
there's no best language, there has never ever been a best language,
-
1:13:07
there will never ever be a best language, right.
-
1:13:09
It depends on the programmer, it depends on the system,
-
1:13:14
it depends on the requirements of the software, there's no such thing as a best.
-
1:13:20
There's no best text editor, there's no best IDE, there's no best web browser,
-
1:13:23
there's no best language, there's no best anything.
-
1:13:29
Yeah, okay.
-
1:13:30
Shamul, you wanna learn more about Python,
-
1:13:34
well I heavily recommend Treehouse for that.
-
1:13:37
[LAUGH] But if you don't wanna pay for Treehouse or
-
1:13:41
you can't afford Treehouse, which is totally fine and
-
1:13:46
understandable, then there is pretty good tutorials on python.org.
-
1:13:52
And there's a couple of amazing books out there,
-
1:13:56
Automate The Boring Stuff by Al Sweigart is free online I do believe.
-
1:14:01
Let's look that up real quick, Automate The Boring Stuff.
-
1:14:06
And then Python Crash Course or Crash Course Python,
-
1:14:12
I don't remember which one of those it is, is a really great book as well and
-
1:14:17
I highly, highly recommend both of those.
-
1:14:21
There you go, try that out.
-
1:14:24
So yeah, let's talk about this Rust script real quick and
-
1:14:27
then we'll go do something else.
-
1:14:29
Somebody else challenged me to a Code Fights fight,
-
1:14:36
that was fun to do so yeah, somebody come fight me on this.
-
1:14:42
My username is KennethLove, I'm really hard to pick out, you'll never find me.
-
1:14:49
All right cool, so this is a number guessing game, right, so let's run this.
-
1:14:58
So it's a number between 1 and 100 so let's guess 50,
-
1:15:01
that's too small so let's guess 75, that's too big.
-
1:15:06
So it's between 50 and 75, let's go for 65, that's too big.
-
1:15:12
So it's between 50 and 65, let's go for 60, too big, 55,
-
1:15:18
too small, 57, too small, 58, then it's gotta be 59.
-
1:15:23
Sweet, and it took me eight tries.
-
1:15:28
So some of this is my own thing that I added,
-
1:15:31
which is the how many guesses you spent, the rest of it is from the tutorial.
-
1:15:37
So we're bringing in this random crate.
-
1:15:41
Sure, Humanoid, I'll do another one against you.
-
1:15:44
And then kind of like with Python, kind of like with Java,
-
1:15:47
we have to bring in packages to be able to use them.
-
1:15:51
So in this case we're bringing in the IO package from the standard library.
-
1:15:54
We're bringing in the ordering package from the comparison package
-
1:15:58
inside the standard library.
-
1:15:59
They're actually not called packages, they're called crates,
-
1:16:04
Rust has crates which is weird but whatever.
-
1:16:08
And then here we're bringing in the Rng thing,
-
1:16:13
whatever that is, from the rand crate.
-
1:16:17
And then inside of our main function we print out guess the number,
-
1:16:22
then we generate a random number between 1 and 101.
-
1:16:26
And then here I'm creating a variable called num guesses, that's gonna be zero.
-
1:16:32
And this right here, this M-U-T, the mut,
-
1:16:36
makes it mutable, so that makes it to where you can change the value later.
-
1:16:40
Because by default in Rust all variables are immutable,
-
1:16:43
they can never be changed once they're set.
-
1:16:45
And that's actually really cool, that's really,
-
1:16:48
really handy, so yeah, that's amazing.
-
1:16:53
So then this loop here is just an infinite loop, it runs forever,
-
1:16:58
this is the equivalent of Python's while true, right.
-
1:17:02
So that's what you've got.
-
1:17:04
All right Humanoid, I'll fight you in a second.
-
1:17:10
So then we print out put in your guess, and then here we take guess and
-
1:17:15
it's gonna be this new string.
-
1:17:17
This one we mark as being mutable because we wanna change the string
-
1:17:20
once they input one.
-
1:17:22
So we take standard n,
-
1:17:26
we read the line, and then here we're saying give me a reference to guess.
-
1:17:32
Let me play with guess and if it doesn't
-
1:17:38
come back as something that's actually a string for some reason
-
1:17:43
then this expect will come out, or then this will be printed out.
-
1:17:49
So then guess, we're gonna turn that into an unsigned 32 bit number,
-
1:17:54
we're gonna trim it of any white space and then we're gonna parse it,
-
1:17:57
that's what's gonna turn it into that u32.
-
1:18:00
If it parses okay,
-
1:18:03
if it's fine, then we just give back the num, give back the number.
-
1:18:08
And otherwise if it doesn't then we continue with the loop,
-
1:18:11
we do the loop again, okay.
-
1:18:14
And then here I increment the number of num guesses by 1 and
-
1:18:19
we print out here's what you guessed.
-
1:18:21
And then here this is pretty cool, we do a match comparison, so
-
1:18:25
we take guess, we do a comparison on it against the secret number that got picked.
-
1:18:31
If it's less then we say hey, you're number was too small.
-
1:18:35
If it's bigger, if it's greater, than we print out your number's too big.
-
1:18:40
Or if they're equal then we print out you win,
-
1:18:42
here's how many tries it took you, and then we break the loop.
-
1:18:46
This is actually pretty cool, this is really,
-
1:18:50
that's 40 lines of code and that's pretty amazing.
-
1:18:55
We did a number guessing game almost exactly like this,
-
1:18:58
in Python Basics I think it was, one of my courses,
-
1:19:02
it took us way more than 40 lines to do it, so that's pretty cool.
-
1:19:07
I think Rust is neat, so
-
1:19:11
yeah, hopefully ya'll will, you'll check out Rust.
-
1:19:15
They have a tutorial on the official site that's really good so try that out.
-
1:19:19
Okay we got a new challenge, so Humanoid wants to challenge me again.
-
1:19:25
Segar says there's a Vimium Chrome extension,
-
1:19:30
I may have to check that out, I may have to give that a try.
-
1:19:32
Tska-craft wants to know how they can work for
-
1:19:36
Treehouse if they become good in one of the languages that we use.
-
1:19:40
We hire every once in a while, it's always possible, but
-
1:19:45
$1,000 per hour that's probably not gonna happen.
-
1:19:51
Just because, yeah, nobody's gonna get paid a $1,000 an hour.
-
1:19:58
$1,000 and hour if you wanna work a really small number of hours.
-
1:20:01
Sure, all right, humanoid, let's do this again.
-
1:20:05
I'm gonna take a minute off for
-
1:20:07
everyone of these maybe two just because of me reading it.
-
1:20:11
Okay given three integers, a, b, and c.
-
1:20:14
It's guaranteed that two of these Integers are equal to each other.
-
1:20:16
What is the value of the third Integer?
-
1:20:21
Bug fix task, aw, man.
-
1:20:24
Okay, extra number, if a equal to b returns c, if c not is,
-
1:20:38
That's just silly, all right, next.
-
1:20:42
Given a permutation, produce its inverse permutation.
-
1:20:45
Permutation one, three, four, two, the output should be one, four, two, three.
-
1:20:55
[MUSIC]
-
1:21:04
Okay, resulting those blank for i in range that result that append that for
-
1:21:10
i in range, the length of permutation result permutation i
-
1:21:15
minus 1 equals Result.
-
1:21:26
Okay, so that became 1.
-
1:21:28
2 became 3, [NOISE] this is one I'm not sure of,
-
1:21:36
because I'm not sure what
-
1:21:41
they're trying to do here.
-
1:21:45
List index out of range, yeah, of course it is, because,
-
1:21:58
No, this one doesn't count, this one's impossible,
-
1:22:00
I've had it before I never mentioned this.
-
1:22:02
Okay, I get the rules, I don't get the reverse permutation.
-
1:22:10
Let's go look at, well that's not gonna help me.
-
1:22:15
An inverse permutation is a permutation in which each number and
-
1:22:19
the number of the place which it occupies are exchanged.
-
1:22:25
Each number and the number of the place that it occupies
-
1:22:34
So 1 stayed in 1, 3, 0,
-
1:22:38
1, 2, 3 went to there,
-
1:22:42
4 went to there, 2 went to there?
-
1:22:49
But 4 is not in the right place, shouldn't 4 be,
-
1:23:03
And in first permutation, is a permutation in which each number and
-
1:23:08
the number of the place it occupies are exchanged.
-
1:23:22
Okay, I wanna see what this test look like.
-
1:23:24
Okay, that's that one, 1, 2, 3 check him out as 1, 2, 3,
-
1:23:29
because 1 stays in 1, 2 stays in 2, 3 stays in 3.
-
1:23:34
Here, 1 stays in 1.
-
1:23:42
Okay, do any of you all get this one?
-
1:23:43
[LAUGH] Cuz I am lost on this one.
-
1:23:48
Okay, let's just look at what the code is doing, so we have a blank list.
-
1:23:53
So then, for each number in a range the link of the permutation,
-
1:23:57
we're appending 0, okay?
-
1:24:01
So then, for an index, for the length of the permutation,
-
1:24:07
we take the permutation that number minus 1.
-
1:24:14
So, That's gonna be 0 or whatever.
-
1:24:23
So that first one's gonna be negative 1 and that should equal,
-
1:24:37
I don't think that's right, I can only change dot, dot, dot, confirm.
-
1:24:53
You know what they want, but you don't know how to do it?
-
1:24:55
Well, you're doing better than me on that one then.
-
1:25:01
So 1 stays in 1, The number and
-
1:25:07
the number of the place which it occupies.
-
1:25:14
[MUSIC]
-
1:25:23
Okay, okay, okay hold on.
-
1:25:25
So this is gonna take permutation i minus 1, right?
-
1:25:30
So that's gonna be permutation i, the first one is gonna be 1.
-
1:25:37
Minus 1 gonna be 0, so that should be equal
-
1:25:43
to something, let's not worry about that one.
-
1:25:48
The next one that comes through is gonna be 3, 3 minus 1 equals 2.
-
1:26:02
3 minus 1 equals 2, so that's the second spot,
-
1:26:08
[MUSIC]
-
1:26:21
[LAUGH] Yeah, this one, the number, so if we went to the end, the inverse is to, so,
-
1:26:27
yeah, the number goes where the item and the array at the index that is the number.
-
1:26:33
The number goes where the item and
-
1:26:37
index array at the index that is the number.
-
1:26:41
But there's no 0 in here, so
-
1:26:45
[LAUGH] one goes into 1, 4 goes into 2.
-
1:26:54
I can't make four cases Skycode,
-
1:26:56
I can't change the code beyond what I'm going right now.
-
1:27:01
Okay, I'm gonna look at this, I'm gonna get this one.
-
1:27:09
That one passed, cuz I basically sorted the thing.
-
1:27:13
Okay, so they're expecting 4 to come into the second one.
-
1:27:16
So we've got 3 which is at index 2 b Three ends up at index three.
-
1:27:24
The number goes where the item in the index at the index that is the number.
-
1:27:35
Yeah, how is this not just permutation[i]?
-
1:27:41
Like that can't be right,
-
1:27:48
yeah, 2, 4, 1,
-
1:27:53
3, yeah, whatever
-
1:28:13
Okay, I'm just gonna skip this one,
-
1:28:15
I don't even care at this point [LAUGH] we'll figure it out later.
-
1:28:19
Okay, given a string replace each, you skipped it too.
-
1:28:23
[LAUGH] Given a string replace each of its characters by
-
1:28:27
the next one in the English alphabet.
-
1:28:30
0 would be replaced by a, so
-
1:28:36
we're shifting it by 1,
-
1:28:41
okay, for letter in input string.
-
1:28:48
Now, let's do output is that.
-
1:28:52
If letter is equal to a,
-
1:28:57
output.append z elif letter
-
1:29:03
equal to z output.append('a') else,
-
1:29:21
Is it always gonna be lowercase?
-
1:29:22
It's always gonna be lowercase.
-
1:29:23
Okay, else
-
1:29:28
Output.append(string.ascii) lowercase,
-
1:29:44
String.ascii_lowercase.index[letter] plus 1.
-
1:29:55
[MUSIC]
-
1:30:00
return.joint(output).
-
1:30:03
[MUSIC]
-
1:30:13
I don't need this.
-
1:30:14
[MUSIC]
-
1:30:22
I just need this.
-
1:30:24
[MUSIC]
-
1:30:27
There we go.
-
1:30:28
[MUSIC]
-
1:30:34
We're still waiting on you.
-
1:30:35
[MUSIC]
-
1:30:40
3 is the second number, so goes where number 2 is placed.
-
1:30:45
[MUSIC]
-
1:30:50
Okay, Daithi, I think I get that.
-
1:30:52
So because 3 was the second item, we go back one to get 2, we find where the 2 is?
-
1:30:59
[MUSIC]
-
1:31:04
Yeah, I got no idea on that one.
-
1:31:06
Let's look that up, let's do Python inverse per mutation, right?
-
1:31:14
[MUSIC]
-
1:31:21
Okay, so let's see what they're doing.
-
1:31:22
[MUSIC]
-
1:31:24
So they make an array of zeroes,
-
1:31:27
that's the length of the permutation, which is fine.
-
1:31:32
For each thing in enumerate, yeah
-
1:31:34
[MUSIC]
-
1:31:38
Inverse, whatever the letter is equals that.
-
1:31:40
Yeah, see that would make so much more sense.
-
1:31:43
But they weren't doing that.
-
1:31:45
[MUSIC]
-
1:31:49
They were doing something weird.
-
1:31:52
I lost that one again?
-
1:31:53
By three seconds?
-
1:31:55
[LAUGH] By three seconds, really?
-
1:31:58
[MUSIC]
-
1:32:00
I lost by three seconds.
-
1:32:02
Aw man, that's ridiculous.
-
1:32:06
That's absolutely ridiculous.
-
1:32:09
All right we got time.
-
1:32:10
Send me another one or somebody else send me one and
-
1:32:12
let's answer some more questions.
-
1:32:14
Somebody send, give me some more questions.
-
1:32:18
[MUSIC]
-
1:32:21
And we'll talk about whatever.
-
1:32:25
Deiphy, do you think you've got something?
-
1:32:29
What's, So see, Sagar, I don't get that one, right?
-
1:32:38
1, 2, 3, 4, 5, The 2 is in position 1.
-
1:32:52
How does it go to the end?
-
1:32:54
[MUSIC]
-
1:33:00
So zeros index stays.
-
1:33:02
All the other items are placed inversely in terms of indexing.
-
1:33:06
[MUSIC]
-
1:33:10
Okay, pause,
-
1:33:13
let's do it pause, let's do it.
-
1:33:21
This could be a really good way to just test things to play with stuff.
-
1:33:27
All of you all have way more stars than me, and
-
1:33:29
it's because I don't ever play with this.
-
1:33:31
But you also all smart cuz Python 2 And that's just ridiculous.
-
1:33:37
[MUSIC]
-
1:33:38
Okay, given integer n, find n factorial.
-
1:33:41
Okay, so factorial of n blah, blah, blah.
-
1:33:45
So is this a bug fixed one.
-
1:33:46
Okay, so yeah, so we do that.
-
1:33:50
I got that one, okay.
-
1:33:52
I've done factorials before
-
1:33:53
[MUSIC]
-
1:33:58
Yeah, if you go ahead and explain I would love
-
1:34:04
to hear an explanation because I am so lost on that.
-
1:34:10
I am also lost on code fights,
-
1:34:13
it is not not letting me start these fights.
-
1:34:18
[LAUGH] Don't let me start fights, that sounds horrible.
-
1:34:22
But yeah, y'all know what I mean.
-
1:34:27
Why is programming not in our life for real,
-
1:34:29
why are there no programs to see if everyone is doing their job or not?
-
1:34:33
I'm kinda glad there's not.
-
1:34:36
Humanoid, you're marked as Python 2.
-
1:34:39
You better fix that, fix it.
-
1:34:42
I'm kinda glad that there's not.
-
1:34:44
As much as programming in real life would be fun for
-
1:34:48
being able to apply functional programming to some job I have to do and
-
1:34:52
Python washes all the dishes for me or whatever.
-
1:34:58
Yeah, I'm not all that stuck on like, I want there to be coding to monitor me.
-
1:35:06
There already is coding to monitor me all day, every day.
-
1:35:10
But [LAUGH] I don't want that to be Something I have to actually deal with.
-
1:35:16
It's just the default, and you never bothered to change it.
-
1:35:18
Well, that's just unacceptable.
-
1:35:20
You gotta have Python 3.
-
1:35:22
We gotta show that Python 3 is better and
-
1:35:26
larger and bigger than Python 2 because it is.
-
1:35:33
All right, we're gonna do this pause as soon as code fights plays along.
-
1:35:42
I'm actually really glad programming is not in real life.
-
1:35:44
Programming is already taken too seriously already.
-
1:35:49
If n is equal to zero, return n Return n.
-
1:35:57
Otherwise, we need to return
-
1:36:03
Else return n- 1.
-
1:36:19
I can't edit all those lines.
-
1:36:22
I keep forgetting that the first one is a bug fix.
-
1:36:25
I keep forgetting that the first one is a bug fix.
-
1:36:29
This should be *=
-
1:36:39
Yeah, see look, this says I'm already at two minutes.
-
1:36:41
I'm nowhere near two minutes.
-
1:36:43
The sample tests aren't even loaded James, what is my most proud Python project?
-
1:36:52
My most proud Python project is probably a package called Jinja Braces.
-
1:36:57
It's a bunch of code a friend and I wrote for Jango's class base views.
-
1:37:05
So it's a lot of stuff for Bringing in
-
1:37:09
a lot of functionality into the class face views without having to write at yourself.
-
1:37:13
It's pretty popular, or was at one time.
-
1:37:16
And yeah, it's pretty neat.
-
1:37:20
Yeah see, this is ridiculous.
-
1:37:22
It's telling me I'm at two minutes and forty something seconds.
-
1:37:25
This thing right here doesn't even exist.
-
1:37:30
Code Fights is ridiculous.
-
1:37:33
Dythe has an explanation for us.
-
1:37:35
So let's see here.
-
1:37:36
One is in position one so it stays in position one.
-
1:37:39
Okay, we all understand and agree with that one.
-
1:37:42
Three is the second number so it goes where ever number two is placed.
-
1:37:47
I get you, okay.
-
1:37:49
Four is the third number so,
-
1:37:50
it goes wherever number three is originally placed.
-
1:37:52
We'd go so on and so forth.
-
1:37:55
I got ya, okay.
-
1:37:57
That makes sense.
-
1:37:59
That makes a lot of sense.
-
1:38:01
The other stuff is a little weird.
-
1:38:06
I'm still trying to figure that one out.
-
1:38:08
Cool, I gotcha now.
-
1:38:10
[MUSIC]
-
1:38:14
Yeah, I kind of wanna try that one again, but-
-
1:38:17
[MUSIC]
-
1:38:25
This is ridiculous.
-
1:38:27
[LAUGH] What is up with code fights?
-
1:38:30
Okay, let's unblock their stuff and see if that makes it work better.
-
1:38:35
I won't block anything, code fights, you can show me your stupid ads or whatever.
-
1:38:39
And we'll see if that works better.
-
1:38:42
Cuz I have not spent four minutes on this.
-
1:38:44
Y'all have seen this.
-
1:38:46
I'm sorry.
-
1:38:47
Dahee, okay.
-
1:38:49
Dahee, that's cool.
-
1:38:50
I will do my best to remember that Dahee.
-
1:38:56
All right, So four and a half minutes later.
-
1:39:05
We still haven't loaded the fight.
-
1:39:07
[LAUGH] That's just ridiculous, what is,
-
1:39:12
okay, I'm just gonna get out of that, okay.
-
1:39:18
Code fights, fix your sight y'all.
-
1:39:21
I know you're watching This is the most important stream ever for code fights.
-
1:39:25
I know code fights is paying attention to this,
-
1:39:27
so that's why I'm looking at the camera.
-
1:39:29
Codefights, fix your site.
-
1:39:33
Look at this, this is, look at this, look a this mess.
-
1:39:36
It's not even loading, it's like five minutes.
-
1:39:43
Humanoid I see the chat probably a little bit
-
1:39:45
faster before it shows up on the screen, but not by much.
-
1:39:49
It definitely takes it a little while to show up.
-
1:39:53
BlameYouTube and Twitch.
-
1:39:56
And beam a little bit because they
-
1:40:01
all have to show up at the same time.
-
1:40:06
Okay, so I said this was times equals,
-
1:40:09
which I can't type an equals sign to save my life.
-
1:40:13
Run those sample tests.
-
1:40:15
[SOUND]?
-
1:40:22
[SOUND]
-
1:40:33
Yeah.
-
1:40:46
[SOUND] I know how a factorial works, I think.
-
1:40:49
So in 5, we start at 5, immediate five,
-
1:40:53
and doesn't equal zero, so then we would return.
-
1:40:58
[SOUND]
-
1:41:03
This is one!
-
1:41:10
[SOUND] You wanna not.
-
1:41:16
[SOUND] Can only change one, okay.
-
1:41:17
Reset, whatever.
-
1:41:19
[SOUND]
-
1:41:22
There we go.
-
1:41:31
Okay, that was not five minutes and something.
-
1:41:33
You all know that.
-
1:41:34
James Scott, I'm using an app called OBS and a service called Restream.
-
1:41:39
Restream.io lets me send the one stream out to multiple end points.
-
1:41:47
Okay, given the number of green apples on a shelf and a total number of apples,
-
1:41:50
return the percentage, excuse me, of green apples.
-
1:41:54
Really?
-
1:41:57
That sounds easier than it should be.
-
1:42:02
[LAUGH] But let's try it.
-
1:42:06
Okay, so return total divided by green times 100.
-
1:42:14
And it looks like you want an int out of that, so int.
-
1:42:19
[SOUND] I don't know,
-
1:42:24
that should be green out of total.
-
1:42:32
What am I doing?
-
1:42:35
[SOUND] Look at me failing.
-
1:42:40
Failing fourth grade math.
-
1:42:47
All right, so the longest diagonals of a square matrix are defined as follows.
-
1:42:53
The first longest diagonal goes from the top left corner to the bottom right one.
-
1:42:57
The second longest diagonal goes from the top right corner to the bottom left one.
-
1:43:01
Given a square matrix,
-
1:43:02
your task is to reverse the order of elements on both of its longest diagonals.
-
1:43:08
Reverse the order of elements on both of its longest diagonals.
-
1:43:13
Okay, so that means I want to take the first item from the first list and
-
1:43:19
swap it with the last item from the last list and
-
1:43:22
then the last item from the first list with the first item from the last list.
-
1:43:26
The middle item stays the same.
-
1:43:29
Okay, that seems simple enough.
-
1:43:32
Okay, so let's look back over here.
-
1:43:35
Poss wants to practice a bit more.
-
1:43:38
You're fine.
-
1:43:39
Don't worry about it.
-
1:43:39
You're doing great.
-
1:43:42
James has an app OBS, cool.
-
1:43:44
Why don't we keep C++ or C at Treehouse?
-
1:43:48
We don't really find them necessary.
-
1:43:52
It's friendly enough but it just doesn't need to be.
-
1:43:57
Okay, so the length of
-
1:44:01
the matrix is always, okay.
-
1:44:07
[SOUND] But they're not always the same
-
1:44:12
[MUSIC]
-
1:44:15
Aha, okay.
-
1:44:17
So, diagonals.
-
1:44:22
[SOUND] All right, so
-
1:44:27
let's get diagonals = 0.
-
1:44:33
It's always gonna be 0.
-
1:44:34
[SOUND] I wanna make pairs of these.
-
1:44:37
0 and then
-
1:44:42
matrix.
-
1:44:47
[MUSIC] And then matrix- 1.
-
1:44:50
[SOUND] Right?
-
1:44:54
I may be doing this in a really long, drawn out way.
-
1:44:58
[SOUND] So then. [MUSIC]
-
1:45:01
Yeah, yeah, yeah, let's do this.
-
1:45:06
So for x.
-
1:45:07
[MUSIC]
-
1:45:12
No.
-
1:45:12
For I in
-
1:45:15
range(len(matrix))-
-
1:45:25
1.
-
1:45:27
[MUSIC]
-
1:45:41
.append and
-
1:45:44
we're going to append i and
-
1:45:50
then len(matrix)- i + 1.
-
1:45:56
[MUSIC]
-
1:46:02
So I'll break this onto a new line so y'all can see what I'm doing.
-
1:46:06
So, we're appending.
-
1:46:07
In this case, it would be 0 and then 9, right?
-
1:46:14
[MUSIC]
-
1:46:25
Or we just want I + 1,
-
1:46:27
[MUSIC]
-
1:46:31
Times -1 which I wanna reverse that.
-
1:46:35
[MUSIC]
-
1:46:37
Okay, so I think that will work.
-
1:46:40
So the new_matrix = this.
-
1:46:47
It's an empty list.
-
1:46:50
[SOUND] for
-
1:46:53
m in matrix.
-
1:46:58
So for each item in the matrix, I want an index on that too, enumerate.
-
1:47:04
[MUSIC]
-
1:47:21
new_matrix.
-
1:47:22
[MUSIC]
-
1:47:31
new_line =.
-
1:47:32
[MUSIC]
-
1:47:41
I am lost on this one.
-
1:47:42
I need code to sit down and think this one through but, okay.
-
1:47:49
So I want to take the first item on the first one.
-
1:47:56
[MUSIC]
-
1:48:07
So that's gonna be equal to m.
-
1:48:11
Whatever is in m, and then we wanna take new_line.
-
1:48:16
[MUSIC]
-
1:48:21
And we wanna take
-
1:48:25
diagonals I, 0.
-
1:48:30
So whatever that item is, and we want that to be equal to.
-
1:48:37
[MUSIC]
-
1:48:41
We don't even need that.
-
1:48:42
[MUSIC]
-
1:48:45
We don't even need that.
-
1:48:46
Okay, so we can just do this.
-
1:48:48
We can do matrix, which means really I can do this as for In,
-
1:48:54
[MUSIC]
-
1:48:57
range(len(matrix)), right?
-
1:49:03
So, matrix, the one that we're on.
-
1:49:10
[SOUND] The zeroth item.
-
1:49:12
Whatever item comes out of diagonals.
-
1:49:16
There.
-
1:49:17
[MUSIC]
-
1:49:32
Is equal to matrix.
-
1:49:34
[MUSIC]
-
1:49:40
I + 1 times -1,
-
1:49:48
diagonals I, 1
-
1:49:56
[MUSIC]
-
1:50:04
I don't think I'm quite right on that one.
-
1:50:07
[MUSIC]
-
1:50:21
Okay, That should always go to the other side.
-
1:50:29
[MUSIC]
-
1:50:36
>> That should always get the last item, right?
-
1:50:38
And I don't need new_matrix.
-
1:50:43
[MUSIC]
-
1:51:23
The code's fine.
-
1:51:23
This should be minus one.
-
1:51:31
So some of these I got completely wrong.
-
1:51:35
Yeah, ha ha, end is going to be equal to matrix.
-
1:51:45
Matrix i plus 1 times
-
1:51:50
negative 1 diagonals, i negative 1.
-
1:51:57
Okay, so that's the last value, right?
-
1:52:02
So, and then let's say start is equal to matrix
-
1:52:10
I diagonals I zero,
-
1:52:15
okay, so that's the start value and that's the last value.
-
1:52:19
So the start value is gonna be equal to end.
-
1:52:25
And the last value here is gonna be equal to start.
-
1:52:29
And run those tests.
-
1:52:33
No.
-
1:52:43
I forgot to get the last one.
-
1:52:50
Okay, I'm- [SOUND] Okay, so
-
1:52:55
I also have to get, The last one on the end.
-
1:53:01
Can you create a string and swap the numbers there and
-
1:53:04
recreate a square matrix?
-
1:53:06
I probably could on that one.
-
1:53:10
All right lets see if I can remember
-
1:53:14
it was [INAUDIBLE] Did I get that one right?
-
1:53:21
I could probably do that one.
-
1:53:25
Strings, swap the numbers, then recreate a square matrix.
-
1:53:28
It's not any easier with a string than it is with a list, so
-
1:53:39
So it's fine, okay.
-
1:53:40
Here, we'll do this.
-
1:53:41
We'll do Start Left, End Right, and
-
1:53:47
we'll do Start Right and End Left.
-
1:53:51
So Start Right Is gonna be equal to matrix, i,
-
1:53:58
so whatever road we're on, -1, right?
-
1:54:04
Always, and this is gonna be equal to matrix
-
1:54:08
[MUSIC]
-
1:54:14
Here,
-
1:54:14
[MUSIC]
-
1:54:19
Zero always, right?
-
1:54:22
So then this one here ends up equaling
-
1:54:27
and_right and matrix i- 1,
-
1:54:31
it's not always gonna be- 1 though.
-
1:54:45
That's gonna be equal to that.
-
1:54:45
This one,
-
1:54:54
Here This
-
1:54:59
last one will be equal to start left, this one will be equal to start right.
-
1:55:04
This isn't exactly right.
-
1:55:07
This is totally wrong.
-
1:55:16
Invalid syntax, yeah you're right.
-
1:55:19
[MUSIC]
-
1:55:42
How did that come out as 4?
-
1:55:44
Because of that -1, So.
-
1:55:55
All right, I'm not worried about this one,
-
1:55:58
[LAUGH] I'm giving up on this one, you beat me on this, Humanoid,
-
1:56:07
we'll find out what happens later, So, yeah so we're at the end of a stream.
-
1:56:14
Let's take questions.
-
1:56:17
Anybody have questions let me know.
-
1:56:20
If I have another code fight here I will check it out later.
-
1:56:29
Okay, it's just that one.
-
1:56:31
Anybody that wants to challenge me go for
-
1:56:33
it, I don't know how often I'll be checking out, but I will later so
-
1:56:37
we'll talk about that.
-
1:56:39
If you have any questions ask them now I'll answer them before the end of
-
1:56:42
the stream.
-
1:56:43
And Critical Toxic would like me to do more discord bots.
-
1:56:46
I think I will actually.
-
1:56:49
It's a new level, woo.
-
1:56:51
And I lost because that totally took me 6 minutes and 53 seconds.
-
1:56:54
Totally, 100%, right humanoid?
-
1:56:56
There's no way that didn't take me seven minutes.
-
1:57:00
Good fight.
-
1:57:03
Okay, whatever.
-
1:57:06
Anyway, so I'll do more discord bots.
-
1:57:11
I wanna do another discord bot.
-
1:57:12
I really wanna do one that's over the Voice feature of discord.
-
1:57:19
But that's gonna be a little ways off.
-
1:57:20
We'll get to that later.
-
1:57:22
But yeah I definitely wanna do more discord bots.
-
1:57:25
If i remember correctly my very first Stream that I did was a Discord bot.
-
1:57:36
No, that was the Django travel blog, right that was something different.
-
1:57:40
Anyway though I will do more Discord bots.
-
1:57:44
I will be streaming over the weekend I will be doing
-
1:57:49
Some streams for the Ludum Dare that I'm doing.
-
1:57:55
So if you want to watch me do panicky Rust code and
-
1:57:59
creative sprites and maps and things like that, be sure to tune in.
-
1:58:03
That will be one my own Beam channel, though.
-
1:58:05
That will be at theme.pro/kennethlove, it won't be here on treehouse.
-
1:58:12
I will not be streaming on treehouse,
-
1:58:13
I'll just be streaming on my own personal channel.
-
1:58:15
So if you wanna come watch that, feel free.
-
1:58:17
You can come and watch.
-
1:58:19
I'd love to have you there.
-
1:58:20
I'll have chat open.
-
1:58:22
We can talk about stuff.
-
1:58:23
It may be just music playing or something, or it may be Something else.
-
1:58:29
I'm not sure. I don't know if
-
1:58:30
there will be any audio or not.
-
1:58:31
You may just get to watch me type and put down pixels.
-
1:58:34
So, thank you all for watching.
-
1:58:36
Glad to have had you here.
-
1:58:38
Tune in next week.
-
1:58:39
We'll do something else.
-
1:58:40
I think I'm going to start doing.
-
1:58:41
I want to start playing around with languages, so if you all would like to see
-
1:58:45
me Do tutorials, practice learn different languages.
-
1:58:49
Let me know what different languages you like to see and maybe I'll do some.
-
1:58:52
It will be a lot of mistakes.
-
1:58:56
Many mistakes will be made, but that's fine.
-
1:58:59
Mistakes are how we learn.
-
1:59:00
So, thank you all for watching and I will see you all next week.
-
1:59:05
Have a great weekend.
You need to sign up for Treehouse in order to download course files.
Sign up