Games & Quizzes
Don't forget to Sign In to save your points
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
Games & Quizzes
You may need to watch a part of the video to unlock quizzes
Don't forget to Sign In to save your points
PERFECT HITS | +NaN | |
HITS | +NaN | |
LONGEST STREAK | +NaN | |
TOTAL | + |
all right hello world this is cs50 live
all right hello world this is cs50 live
my name is Colton Ogden today we're
my name is Colton Ogden today we're
joined by the man himself
joined by the man himself
David Malin hello everyone good to see
David Malin hello everyone good to see
everyone on stream and not just in the
everyone on stream and not just in the
chat today we are doing something pretty
chat today we are doing something pretty
cool today pretty fun we're doing a from
cool today pretty fun we're doing a from
scratch of Python tutorial and my
scratch of Python tutorial and my
understanding is that you've actually
understanding is that you've actually
brought some questions and topics
brought some questions and topics
problem challenges that I haven't seen
problem challenges that I haven't seen
that we're gonna implement and I'm gonna
that we're gonna implement and I'm gonna
sort of be a proxy to somebody who maybe
sort of be a proxy to somebody who maybe
is learning for the first time indeed so
is learning for the first time indeed so
I'm gonna pretty much assume that Colton
I'm gonna pretty much assume that Colton
may or may not actually know Python and
may or may not actually know Python and
so along the way we'll try to solve some
so along the way we'll try to solve some
problems actively by a coding we'll pull
problems actively by a coding we'll pull
things up by Google or Stack Overflow as
things up by Google or Stack Overflow as
we go and frankly try to approximate the
we go and frankly try to approximate the
experience that Colton and I arguably do
experience that Colton and I arguably do
every day when we're writing code to
every day when we're writing code to
sort of figure out problems that we
sort of figure out problems that we
cannot get solved sure I guess maybe we
cannot get solved sure I guess maybe we
should start off first off by maybe
should start off first off by maybe
explaining what Python is and the honest
explaining what Python is and the honest
folks we've advertised this as sort of
folks we've advertised this as sort of
an experience for people who may not
an experience for people who may not
have even programmed or read but at
have even programmed or read but at
least have not programmed in Python
least have not programmed in Python
before yeah so why don't we assume that
before yeah so why don't we assume that
no one here is really that familiar with
no one here is really that familiar with
Python but if you are that's fine
Python but if you are that's fine
hopefully we can fill in some gaps in
hopefully we can fill in some gaps in
your knowledge stop us at any point via
your knowledge stop us at any point via
the chat if you have a question there's
the chat if you have a question there's
no dumb questions here if we take them
no dumb questions here if we take them
for granted that you know what some top
for granted that you know what some top
concept is or some function is or some
concept is or some function is or some
feature just chime and say hey everyone
feature just chime and say hey everyone
what what did they mean by that and so
what what did they mean by that and so
that we can answer here on stream so
that we can answer here on stream so
Python is a very popular programming
Python is a very popular programming
language it's a little different from
language it's a little different from
languages like C and C++ and a few
languages like C and C++ and a few
others that you would traditionally
others that you would traditionally
compile recall that if you've ever
compile recall that if you've ever
programmed in one of those languages you
programmed in one of those languages you
have to actually run some program called
have to actually run some program called
a compiler to convert your source code
a compiler to convert your source code
the text that you write to machine code
the text that you write to machine code
the zeros and ones that the computer
the zeros and ones that the computer
actually understands nice thing about
actually understands nice thing about
Python is that we don't have to do that
Python is that we don't have to do that
what would is you want to characterize
what would is you want to characterize
Python for folks to distinguish it from
Python for folks to distinguish it from
that process yeah no I mean Python is
that process yeah no I mean Python is
nice it's it's essentially it runs
nice it's it's essentially it runs
almost in this it's called a virtual
almost in this it's called a virtual
machine but it's almost like having a
machine but it's almost like having a
computer inside a computer and it
computer inside a computer and it
executes these you know with the
executes these you know with the
traditional programming language you're
traditional programming language you're
writing text and I'll switch over to my
writing text and I'll switch over to my
computer here just that we can maybe
computer here just that we can maybe
frame this visually a little bit better
frame this visually a little bit better
but not Chrome in BS code by the way
but not Chrome in BS code by the way
this is my text editor of choice it just
this is my text editor of choice it just
vs code you need in order to
vs code you need in order to
any source code some sort of text editor
any source code some sort of text editor
application you can even use something
application you can even use something
like text edit for example if I pull it
like text edit for example if I pull it
TextEdit on my Mac it's a I'm not sure
TextEdit on my Mac it's a I'm not sure
what that email is there but I think
what that email is there but I think
that might have been from another stream
that might have been from another stream
but essentially what you do is you you
but essentially what you do is you you
have some program that you can write
have some program that you can write
text into and usually you don't want to
text into and usually you don't want to
write it in what's called rich text or
write it in what's called rich text or
you have formatting you write it in
you have formatting you write it in
plain text like this and you write your
plain text like this and you write your
instructions to the computer a bunch of
instructions to the computer a bunch of
lines tell the computer icon
lines tell the computer icon
no this isn't quite Python not unless
no this isn't quite Python not unless
you're unless you don't know how to
you're unless you don't know how to
write good variable names to say this
write good variable names to say this
might look and this might be some
might look and this might be some
people's Python code but you essentially
people's Python code but you essentially
go through and you write a set of
go through and you write a set of
instructions for the computer like this
instructions for the computer like this
top down and the computer will execute
top down and the computer will execute
them but computers don't understand
them but computers don't understand
arbitrary textual information the
arbitrary textual information the
computer can only speak in certain
computer can only speak in certain
languages computer labs specifically its
languages computer labs specifically its
own machine code which is binary code
own machine code which is binary code
which we talked about in cs50 one of the
which we talked about in cs50 one of the
more underlying principles of that David
more underlying principles of that David
has an awesome chance of lectures on our
has an awesome chance of lectures on our
YouTube channel
YouTube channel
but long story short somewhere along the
but long story short somewhere along the
line you have to convert all your
line you have to convert all your
instructions into something that the
instructions into something that the
computer can understand and with
computer can understand and with
traditional language that you alluded to
traditional language that you alluded to
before
before
you do this with the help of a compiler
you do this with the help of a compiler
they take this text and end up
they take this text and end up
translating it into you know they
translating it into you know they
basically this which is the computer's
basically this which is the computer's
native sort of tongue mm-hmm but how is
native sort of tongue mm-hmm but how is
Python different here python is
Python different here python is
different in that it doesn't actually
different in that it doesn't actually
perform this step explicitly along the
perform this step explicitly along the
line it still actually happens but it
line it still actually happens but it
basically translates all the lines that
basically translates all the lines that
you've written when you just load the
you've written when you just load the
script into the program that is itself
script into the program that is itself
called Python yeah and you can think of
called Python yeah and you can think of
Python then is an interpreter this sort
Python then is an interpreter this sort
of middleman that translates between
of middleman that translates between
what you write and what the computer
what you write and what the computer
actually understands so you can think of
actually understands so you can think of
Python the program which will run in
Python the program which will run in
just a couple minutes is a program that
just a couple minutes is a program that
reads your own code top to bottom left
reads your own code top to bottom left
to right and it just does what you say
to right and it just does what you say
you don't have to actually use something
you don't have to actually use something
like Visual Studio or GCC or clang or
like Visual Studio or GCC or clang or
any number of other compilers explicitly
any number of other compilers explicitly
all of that sort of happens before you
all of that sort of happens before you
automatically thanks to the
automatically thanks to the
interpretation process along the way in
interpretation process along the way in
D you can even fire up let's see if if
D you can even fire up let's see if if
you have it installed on your machine
you have it installed on your machine
for example here I have Python three
for example here I have Python three
there's two different versions of Python
there's two different versions of Python
3 long story short Python 3 is the new
3 long story short Python 3 is the new
way
way
the way that is going to be the official
the way that is going to be the official
way very shortly as of 2020 but if I
way very shortly as of 2020 but if I
type Python 3 and my command line
type Python 3 and my command line
assuming you have it installed you can
assuming you have it installed you can
see that I actually have this sort of
see that I actually have this sort of
prompt here these three arrows which
prompt here these three arrows which
append I can actually type in
append I can actually type in
instructions and it will immediately
instructions and it will immediately
execute things for example if I wanted
execute things for example if I wanted
to say print David J Malan like like
to say print David J Malan like like
this assuming that I type it correctly
this assuming that I type it correctly
it'll actually literally do it without
it'll actually literally do it without
needing to do that intermediary
needing to do that intermediary
compilation stuff yeah absolutely this
compilation stuff yeah absolutely this
is an interactive interpreter so we'll
is an interactive interpreter so we'll
just do what you say the downside of
just do what you say the downside of
course is that we're not really saving
course is that we're not really saving
any of our work along the way so it's
any of our work along the way so it's
better generally to write your programs
better generally to write your programs
in an actual text editor like vs code or
in an actual text editor like vs code or
sublime or atom or something else so
sublime or atom or something else so
that you can save your code and let the
that you can save your code and let the
interpreter run it and rerun it again
interpreter run it and rerun it again
and again so why don't we go ahead and
and again so why don't we go ahead and
do that you want to go ahead and open up
do that you want to go ahead and open up
a blank editor window so for those of
a blank editor window so for those of
you following along at home if you want
you following along at home if you want
to go ahead and Google the S code or
to go ahead and Google the S code or
Visual Studio code you're welcome to
Visual Studio code you're welcome to
download the same program for free atom
download the same program for free atom
sublime text and notepad plus plus and a
sublime text and notepad plus plus and a
bunch of others are very popular on Macs
bunch of others are very popular on Macs
and PCs and Linux machines but odds are
and PCs and Linux machines but odds are
if you're tuning in you probably have
if you're tuning in you probably have
some form of text editor but if not feel
some form of text editor but if not feel
free to try one of those and then what
free to try one of those and then what
you should also do if you don't have it
you should also do if you don't have it
already is make sure your computer if
already is make sure your computer if
you do want to follow along has Python
you do want to follow along has Python
installed
installed
so again python is not only a language
so again python is not only a language
it's an interpreter a program that will
it's an interpreter a program that will
understand your use of that language and
understand your use of that language and
if you go to python org slash downloads
if you go to python org slash downloads
you'll find yourself at the official
you'll find yourself at the official
website where you can download the
website where you can download the
python version 3 installer to make sure
python version 3 installer to make sure
that you have that on your machine
that you have that on your machine
depending on how your machine was
depending on how your machine was
configured you may have Python already
configured you may have Python already
as Colton said but it might be an older
as Colton said but it might be an older
version Python 2 that's officially going
version Python 2 that's officially going
to be end-of-life soon that is it's
to be end-of-life soon that is it's
being phased out in favor finally of
being phased out in favor finally of
Python 3 so everything we do today is
Python 3 so everything we do today is
Python 3 specific but beware because
Python 3 specific but beware because
when you're googling when you're looking
when you're googling when you're looking
on Stack Overflow there's a lot of good
on Stack Overflow there's a lot of good
answers to old Python code out there so
answers to old Python code out there so
you don't want to be led astray
you don't want to be led astray
Simo has a sweet comment says david
Simo has a sweet comment says david
because of you i stopped playing video
because of you i stopped playing video
games all day I learned it
games all day I learned it
have a real job at an ecomcon wow that's
have a real job at an ecomcon wow that's
amazing I see Andres taking exception to
amazing I see Andres taking exception to
the fact that we haven't promoted Idol
the fact that we haven't promoted Idol
there's a few other IDE s and editors as
there's a few other IDE s and editors as
well this is not an exhaustive list
well this is not an exhaustive list
what's nice about things like vs code is
what's nice about things like vs code is
that they are first and foremost a text
that they are first and foremost a text
editor and you can layer more features
editor and you can layer more features
on top of them somebody asked out what
on top of them somebody asked out what
the s code am I using I think I'm using
the s code am I using I think I'm using
Dracula right now it's just at the end
Dracula right now it's just at the end
of the last stream but I actually prefer
of the last stream but I actually prefer
the noctus theme so look real quick just
the noctus theme so look real quick just
the important stuff out of the way first
the important stuff out of the way first
this has nothing to do with Python but
this has nothing to do with Python but
we're gonna switch that Noctis color
we're gonna switch that Noctis color
that's the one that I recently have like
that's the one that I recently have like
but they all a lot of the defaults look
but they all a lot of the defaults look
very nice nice and you want it let's go
very nice nice and you want it let's go
ahead and get rid of the Explorer for
ahead and get rid of the Explorer for
now but let's just go ahead and save
now but let's just go ahead and save
this program as hello dot pi so hello is
this program as hello dot pi so hello is
gonna be the name of the program pi
gonna be the name of the program pi
indicates that this is a Python program
indicates that this is a Python program
you don't need number three anywhere in
you don't need number three anywhere in
there you still just use dot pi so our
there you still just use dot pi so our
first program well let's keep it super
first program well let's keep it super
simple and literally write the program
simple and literally write the program
that everyone in the world seems to
that everyone in the world seems to
start writing code in which is just
start writing code in which is just
hello world so instead of David J Malan
hello world so instead of David J Malan
how would you go ahead and Python and
how would you go ahead and Python and
just write a program that prints out
just write a program that prints out
literally hello world
literally hello world
I would I would use the print function
I would I would use the print function
which comes with Python and actually the
which comes with Python and actually the
nice thing about vs code is that it
nice thing about vs code is that it
gives you a lot of this sort of built-in
gives you a lot of this sort of built-in
intelligence depending on how you like
intelligence depending on how you like
to develop or it will actually tell you
to develop or it will actually tell you
when you write functions you know sort
when you write functions you know sort
of what the function it what the
of what the function it what the
function expects what it does so this is
function expects what it does so this is
a nice thing about modern text editors
a nice thing about modern text editors
and integrated development environments
and integrated development environments
IDE using and you said hello world so
IDE using and you said hello world so
I'm just gonna type in the string hello
I'm just gonna type in the string hello
world and that's it yeah but some and
world and that's it yeah but some and
you'll notice now that you get syntax
you'll notice now that you get syntax
highlighting with programs like this I
highlighting with programs like this I
see there's a shout-out to Pi charm as
see there's a shout-out to Pi charm as
well which is a popular editor for
well which is a popular editor for
Python as well yes we do know that IO
Python as well yes we do know that IO
might come with the default installation
might come with the default installation
but we're just we're just focusing on
but we're just we're just focusing on
Python today you can use any text editor
Python today you can use any text editor
out there that you would like it's
out there that you would like it's
amazing folks in the chat are actually
amazing folks in the chat are actually
typing typing some responses to what you
typing typing some responses to what you
said in is that actually this is kind of
said in is that actually this is kind of
interesting because garage burrs wall
interesting because garage burrs wall
actually says print hello world and if
actually says print hello world and if
I'm if I'm reading that correctly
I'm if I'm reading that correctly
he actually said or he or she actually
he actually said or he or she actually
said hello world now if we try to do you
said hello world now if we try to do you
think we should try and run this and
think we should try and run this and
I don't like the squigglies things I
I don't like the squigglies things I
suggest that there's a mistake of some
suggest that there's a mistake of some
sort
sort
so okay undefined variable hello and
so okay undefined variable hello and
this says unexpected token world
this says unexpected token world
interesting
interesting
so let's come let's come back to that
so let's come let's come back to that
though because I think we should run the
though because I think we should run the
program first because while we have
program first because while we have
arguably written a program now we
arguably written a program now we
haven't actually run it previously when
haven't actually run it previously when
Colton ran the program called Python 3
Colton ran the program called Python 3
he was able to write a line of code hit
he was able to write a line of code hit
enter and immediately was executed but
enter and immediately was executed but
typically the paradigm of course for
typically the paradigm of course for
writing code is to write one or more
writing code is to write one or more
lines of code save it in a file and then
lines of code save it in a file and then
somehow execute that file so I think to
somehow execute that file so I think to
execute this file hello dot pi we're
execute this file hello dot pi we're
gonna need a terminal window sure how do
gonna need a terminal window sure how do
we do this so I already have one so this
we do this so I already have one so this
is the Mac native terminal application
is the Mac native terminal application
windows has the same thing with CMD
windows has the same thing with CMD
linux i actually know what's called on
linux i actually know what's called on
linux what's it called of linux terminal
linux what's it called of linux terminal
terminal or x term or any a bunch of
terminal or x term or any a bunch of
other things and so I'm actually I'm
other things and so I'm actually I'm
still in the Python show I'm gonna clear
still in the Python show I'm gonna clear
my screen and then this is assuming that
my screen and then this is assuming that
I'm actually in the directory where
I'm actually in the directory where
we're doing this code so right now we
we're doing this code so right now we
are at my I believe dev is that PWD that
are at my I believe dev is that PWD that
tells you where you're working yeah so
tells you where you're working yeah so
this is per present working directory
this is per present working directory
I'm here users J Harvard dev I want to
I'm here users J Harvard dev I want to
actually go into where I just created
actually go into where I just created
that file which is streams slash Python
that file which is streams slash Python
tutorial and I believe that is where I
tutorial and I believe that is where I
created it and you'll see I hit LS for
created it and you'll see I hit LS for
list and then if I type in Python 3 like
list and then if I type in Python 3 like
we did before to open up the interactive
we did before to open up the interactive
show but instead I say hello dot PI
show but instead I say hello dot PI
after that we'll see that it actually
after that we'll see that it actually
outputs exactly what we wrote in the
outputs exactly what we wrote in the
source code you know and while trivial
source code you know and while trivial
go ahead if you could go back to the
go ahead if you could go back to the
terminal window and just literally run
terminal window and just literally run
Pi Python 3 hello dot PI again this
Pi Python 3 hello dot PI again this
should go without saying but because the
should go without saying but because the
code is saved in file you can of course
code is saved in file you can of course
repeat your steps you can improve on the
repeat your steps you can improve on the
program you can fix bugs again and again
program you can fix bugs again and again
can't do that as easily in just the
can't do that as easily in just the
interactive Church really you lose all
interactive Church really you lose all
that state they've created as soon as
that state they've created as soon as
you exit the interpreter in that context
you exit the interpreter in that context
so the place we usually start when
so the place we usually start when
introducing Python to other students is
introducing Python to other students is
to actually now make the program
to actually now make the program
actually interactive like a program that
actually interactive like a program that
just prints out hello world while sort
just prints out hello world while sort
of nice to be part of that history for
of nice to be part of that history for
posterity it's not particularly
posterity it's not particularly
interactive at all beyond just running
interactive at all beyond just running
it so how would in Python you go about
it so how would in Python you go about
asking a user for his or her name
asking a user for his or her name
and say hello so and so instead of just
and say hello so and so instead of just
hello world all the time well it's
hello world all the time well it's
common in a lot of languages that you
common in a lot of languages that you
get some sort of input function Java has
get some sort of input function Java has
one system dot was its you create a
one system dot was its you create a
scanner at system dot in C use a scanf
scanner at system dot in C use a scanf
and in Python it's actually pretty easy
and in Python it's actually pretty easy
all you have to do is just say let's
all you have to do is just say let's
just say I want to store the user's name
just say I want to store the user's name
in a variable called name and then I'll
in a variable called name and then I'll
sign it whatever the return value of
sign it whatever the return value of
this function input is and notice that
this function input is and notice that
I'm still passing in this string hello
I'm still passing in this string hello
world because when I ask them at the
world because when I ask them at the
command line maybe I'd presumably want
command line maybe I'd presumably want
to prompt them for something or maybe
to prompt them for something or maybe
say in this case not hello world but
say in this case not hello world but
please enter your name colon space okay
please enter your name colon space okay
and then if I wrote let's try it out
and then if I wrote let's try it out
let's go ahead and run it so he notice
let's go ahead and run it so he notice
Colton is using some keyboard shortcuts
Colton is using some keyboard shortcuts
he's sitting up on his keyboard which on
he's sitting up on his keyboard which on
a lot of computers will actually rerun
a lot of computers will actually rerun
the previous command and you can keep
the previous command and you can keep
hitting up up up up to go to previous
hitting up up up up to go to previous
commands further so I'm already
commands further so I'm already
realizing there is gonna be a slight
realizing there is gonna be a slight
issue with this so please enter your
issue with this so please enter your
name let's say my name is Colton and the
name let's say my name is Colton and the
program is over nice which is expected
program is over nice which is expected
yeah I mean you only wrote one line of
yeah I mean you only wrote one line of
code that is asking the user for input
code that is asking the user for input
prompting them for their name and then
prompting them for their name and then
storing that value over on the other
storing that value over on the other
hand side the other side in the name
hand side the other side in the name
variable so what do you want to do next
variable so what do you want to do next
well now since I have name actually
well now since I have name actually
stored somewhere I've set name equals or
stored somewhere I've set name equals or
against the value of input please into
against the value of input please into
your name I can actually reuse that
your name I can actually reuse that
variable so I can say print hello space
variable so I can say print hello space
and then there's multiple ways to do
and then there's multiple ways to do
this which you might have time to look
this which you might have time to look
at but all for now I'll just say hello
at but all for now I'll just say hello
and then I'll actually add a name to
and then I'll actually add a name to
that string like that yeah so what's
that string like that yeah so what's
this plus I mean we're not doing
this plus I mean we're not doing
addition here no so this is common in
addition here no so this is common in
light in a lot of languages if this is a
light in a lot of languages if this is a
term called concatenation where you're
term called concatenation where you're
not actually adding numbers you're
not actually adding numbers you're
actually adding strings you're basically
actually adding strings you're basically
taking one string and sticking another
taking one string and sticking another
string right at the end of it now in the
string right at the end of it now in the
common operator for that use case and
common operator for that use case and
there are multiple operators across
there are multiple operators across
different languages but common is the
different languages but common is the
plus just because it's kind of intuitive
plus just because it's kind of intuitive
okay all right well let's let's go ahead
okay all right well let's let's go ahead
and run this it's now two lines of code
and run this it's now two lines of code
Colton has saved his file he's going
Colton has saved his file he's going
back to the interpreter and running it
back to the interpreter and running it
on this file
on this file
and we say hello comes to work now it's
and we say hello comes to work now it's
kind of a it's kind of a cold hello if I
kind of a it's kind of a cold hello if I
wanted I could probably add maybe a
wanted I could probably add maybe a
exclamation point at the end of it just
exclamation point at the end of it just
to make it a little bit more you know I
to make it a little bit more you know I
guess inviting or friendly or an unhappy
guess inviting or friendly or an unhappy
face to see you oh sure I could say I
face to see you oh sure I could say I
could say hello Colton there we go now
could say hello Colton there we go now
unfortunately that's gonna princess my
unfortunately that's gonna princess my
unhappy face for everyone not just
unhappy face for everyone not just
Colton but even me and for you so why
Colton but even me and for you so why
don't we go ahead and change this I feel
don't we go ahead and change this I feel
like in a lot of programming languages
like in a lot of programming languages
that we've seen that folks out there
that we've seen that folks out there
might have seen you can do things like
might have seen you can do things like
conditions you can do something if
conditions you can do something if
something is true else you can do this
something is true else you can do this
other thing so could we modify this
other thing so could we modify this
program in Python to maybe be happy to
program in Python to maybe be happy to
see anyone except you in which case you
see anyone except you in which case you
should see the unhappy face wow this
should see the unhappy face wow this
feels like a depressing Hayward this is
feels like a depressing Hayward this is
this is what the audience is requested
this is what the audience is requested
how is this okay so we'll say okay so
how is this okay so we'll say okay so
well we're gonna get the name and then I
well we're gonna get the name and then I
want to basically check to see what the
want to basically check to see what the
value of the name is Craig because you
value of the name is Craig because you
said we want the frown to only appear
said we want the frown to only appear
whenever it's me and otherwise
whenever it's me and otherwise
exclamation point I'm assume anything
exclamation point I'm assume anything
else really anything
else really anything
okay so we'll say we'll keep it simple
okay so we'll say we'll keep it simple
so I'll say if name is equal to Colton :
so I'll say if name is equal to Colton :
so this is a Python thing if you want to
so this is a Python thing if you want to
do an if statement you Cokely not : yeah
do an if statement you Cokely not : yeah
Colton : then you say we'll say print
Colton : then you say we'll say print
hello and then we'll do plus name plus
hello and then we'll do plus name plus
and I guess in this case we can even
and I guess in this case we can even
hard code the name since it's specific
hard code the name since it's specific
to this use case and then we'll we'll do
to this use case and then we'll we'll do
the frown actually put a space in front
the frown actually put a space in front
of the smiley face because it was
of the smiley face because it was
getting put right on me let's make sure
getting put right on me let's make sure
we see how unhappy we artists yeah
we see how unhappy we artists yeah
exactly and then we'll just do this
exactly and then we'll just do this
other you know thing if that if
other you know thing if that if
statement doesn't turn out to be the
statement doesn't turn out to be the
case if the name is David or anybody
case if the name is David or anybody
else literally in the entire universe
else literally in the entire universe
then we'll just say else would do what
then we'll just say else would do what
we did before which is just print the
we did before which is just print the
name and then in this case though we do
name and then in this case though we do
want we do want the program to be happy
want we do want the program to be happy
to see who it is so we'll do an exercise
to see who it is so we'll do an exercise
so let's run this and then let's come
so let's run this and then let's come
back and we'll tease apart some of the
back and we'll tease apart some of the
syntax that we've just added sure so
syntax that we've just added sure so
we'll say first of all we'll say David
we'll say first of all we'll say David
so hello David so if he was happy to see
so hello David so if he was happy to see
you very nice and polite how about can
you very nice and polite how about can
we do another one can we do how about
we do another one can we do how about
Richard
Richard
Richard Richard okay so please don't
Richard Richard okay so please don't
your name is Richard okay delightful to
your name is Richard okay delightful to
see you as well
see you as well
okay focus II Richard now let's let's
okay focus II Richard now let's let's
test to see if our functionality is
test to see if our functionality is
correct
correct
ar-ar-ar I guess one off use case and
ar-ar-ar I guess one off use case and
we'll use my name Oh perfect this is man
we'll use my name Oh perfect this is man
this is a good program so far we have a
this is a good program so far we have a
smart smart program that knows the
smart smart program that knows the
appropriate way to address sort of
appropriate way to address sort of
though can you run it one more time and
though can you run it one more time and
it's like an angry person can you type
it's like an angry person can you type
your name in all caps this time oh sure
your name in all caps this time oh sure
absolutely so I'll say Colton oh it's
absolutely so I'll say Colton oh it's
happy to see ya no this is a bug this is
happy to see ya no this is a bug this is
objectively a bug so maybe we're gonna
objectively a bug so maybe we're gonna
take a look at a couple of other
take a look at a couple of other
syntactic features but especially if
syntactic features but especially if
you're a little new to programming but
you're a little new to programming but
you have the right intuition here if
you have the right intuition here if
folks in the chat wouldn't mind
folks in the chat wouldn't mind
proposing what techniques we could use
proposing what techniques we could use
to actually solve this problem we'll go
to actually solve this problem we'll go
back in and fix it in just a minute or
back in and fix it in just a minute or
two Congress that's a feature by the way
two Congress that's a feature by the way
that no that's a bug that's a bug but
that no that's a bug that's a bug but
let's go ahead and back to the code for
let's go ahead and back to the code for
just a moment well folks propose some
just a moment well folks propose some
solutions here perhaps and there's a few
solutions here perhaps and there's a few
questions I had for instance if I'm
questions I had for instance if I'm
coming a Python new what's with the
coming a Python new what's with the
colons like I'm used to the indentation
colons like I'm used to the indentation
but the colons when we're the curly
but the colons when we're the curly
braces the so the nice thing about
braces the so the nice thing about
Python is there are no curly braces
Python is there are no curly braces
mm-hmm the the interesting thing about
mm-hmm the the interesting thing about
Python is that everything is based on
Python is that everything is based on
white space so indentation that blocks
white space so indentation that blocks
no I mean this is something that folks
no I mean this is something that folks
may or may not be familiar with but
may or may not be familiar with but
denoting that something essentially is
denoting that something essentially is
inside of something else is done with
inside of something else is done with
indentation so this if statements like
indentation so this if statements like
body of code that executes when it's
body of code that executes when it's
true we don't use curly break braces
true we don't use curly break braces
like we do in other languages we can't
like we do in other languages we can't
in wait we can't inline it but you would
in wait we can't inline it but you would
instead of doing something like this and
instead of doing something like this and
then having and I actually I'm not 100%
then having and I actually I'm not 100%
sure I think this I think technically is
sure I think this I think technically is
it technically possible to you know it's
it technically possible to you know it's
not I'm getting that conflated with I
not I'm getting that conflated with I
think something else but you don't have
think something else but you don't have
another stream entirely but moving on
another stream entirely but moving on
you you don't need these things you you
you you don't need these things you you
can all you just need to do is make sure
can all you just need to do is make sure
this is indented a certain level within
this is indented a certain level within
this after this if statement here and
this after this if statement here and
now without opening a can of worms
now without opening a can of worms
what's your preference you like tabs you
what's your preference you like tabs you
like spaces I like
like spaces I like
tabs that get converted into spaces okay
tabs that get converted into spaces okay
I'll take that as an acceptable answer
I'll take that as an acceptable answer
indeed in the Python community unlike
indeed in the Python community unlike
most languages there is an accepted norm
most languages there is an accepted norm
or at least a recommended norm which is
or at least a recommended norm which is
to use spaces so let's put an end to
to use spaces so let's put an end to
that debate today we're gonna use spaces
that debate today we're gonna use spaces
for spaces generally would be pretty
for spaces generally would be pretty
common but I like that you don't have to
common but I like that you don't have to
do the the curly braces as you know but
do the the curly braces as you know but
I notice you're also using single quotes
I notice you're also using single quotes
and I feel like in different languages
and I feel like in different languages
and even in Python I sometimes see
and even in Python I sometimes see
single quotes sometimes double quotes
single quotes sometimes double quotes
how do I think about that so there are
how do I think about that so there are
for the for the large part
for the for the large part
interchangeable you can make strings
interchangeable you can make strings
with double quotes you can make strings
with double quotes you can make strings
with single quotes now if you're coming
with single quotes now if you're coming
from a background like C or Java you can
from a background like C or Java you can
only use double quotes for strings but
only use double quotes for strings but
you have to use single quotes for single
you have to use single quotes for single
characters okay Python there's no
characters okay Python there's no
difference there are no there is not
difference there are no there is not
really a by default single character
really a by default single character
versus string when you're using you know
versus string when you're using you know
this apostrophe character or the double
this apostrophe character or the double
quote character so how would people go
quote character so how would people go
about deciding whether on a single quote
about deciding whether on a single quote
kind of person or a double quote kind of
kind of person or a double quote kind of
person well I think that's a matter of
person well I think that's a matter of
taste but if you are use if your string
taste but if you are use if your string
for example contains let's say colton's
for example contains let's say colton's
favorite food pizza we can see that
favorite food pizza we can see that
there's an issue in that different in
there's an issue in that different in
that we see the green that we've seen
that we see the green that we've seen
before with strings after this
before with strings after this
apostrophe up until this apostrophe
apostrophe up until this apostrophe
where we're actually using it for
where we're actually using it for
grammar we're actually using it as a
grammar we're actually using it as a
part of the string itself and there's a
part of the string itself and there's a
couple ways of dealing with this one way
couple ways of dealing with this one way
is we can use the backslash like this
is we can use the backslash like this
and that'll fix it so now we've actually
and that'll fix it so now we've actually
said ignore this apostrophe this is part
said ignore this apostrophe this is part
of the actual string yep Jeanette
of the actual string yep Jeanette
Jeanette sax notes that as well nice but
Jeanette sax notes that as well nice but
let's say I don't like the way that
let's say I don't like the way that
looks I don't like having a backslash to
looks I don't like having a backslash to
start my strings all over the place
start my strings all over the place
instead I can decide in any case where I
instead I can decide in any case where I
do have a single quote inside the string
do have a single quote inside the string
itself I'll use double quotes on the
itself I'll use double quotes on the
outside and because this doesn't match
outside and because this doesn't match
up with this it doesn't cause an error
up with this it doesn't cause an error
in parsing the string nice yeah an
in parsing the string nice yeah an
augment I'm kind of going through an
augment I'm kind of going through an
existential crisis I've been using
existential crisis I've been using
double quotes for like 20 years and
double quotes for like 20 years and
frankly I'm tired of holding the shift
frankly I'm tired of holding the shift
key down and I do think you're seeing in
key down and I do think you're seeing in
more modern Lee popular languages Python
more modern Lee popular languages Python
and JavaScript among them I'm starting
and JavaScript among them I'm starting
to see frankly I think single quotes
to see frankly I think single quotes
more often but you got to beware because
more often but you got to beware because
of the stupid grammar issues alike so
of the stupid grammar issues alike so
just be consistent I think is the point
just be consistent I think is the point
or resort to one or the other when you
or resort to one or the other when you
have two contextual e-commerce a big fan
have two contextual e-commerce a big fan
of single quotes itself as well don't
of single quotes itself as well don't
like whole event sure yeah yeah I know
like whole event sure yeah yeah I know
too much shift at 20 years of hitting
too much shift at 20 years of hitting
the shift key is enough somebody
the shift key is enough somebody
proposed an interesting way of getting
proposed an interesting way of getting
around the the problem yeah let's come
around the the problem yeah let's come
back to that I heard someone propose
back to that I heard someone propose
that we use lower so force the whole
that we use lower so force the whole
string to lowercase I see Richard
string to lowercase I see Richard
proposed using an array or a list in
proposed using an array or a list in
Python where we could check for little
Python where we could check for little
Colton or big Colton or alternating caps
Colton or big Colton or alternating caps
Colton I think the downside there is
Colton I think the downside there is
that you're gonna have an annoying
that you're gonna have an annoying
number of permutations of Colton's if
number of permutations of Colton's if
you will with the C is capitalized or
you will with the C is capitalized or
the O or the L or multiple ones and so
the O or the L or multiple ones and so
forth so I like this lower ID and this
forth so I like this lower ID and this
is actually pretty conventional in a lot
is actually pretty conventional in a lot
of programming languages especially
of programming languages especially
Python when you want to compare
Python when you want to compare
something for equality you canonicalize
something for equality you canonicalize
it so to speak you force it to all
it so to speak you force it to all
lowercase or all lower all lowercase are
lowercase or all lower all lowercase are
all uppercase so that you know
all uppercase so that you know
definitively what you're comparing
definitively what you're comparing
against but you don't want to do it
against but you don't want to do it
destructively you want to do it
destructively you want to do it
essentially temporarily on a copy of the
essentially temporarily on a copy of the
variable right exactly so how could we
variable right exactly so how could we
do that here to make sure that we are
do that here to make sure that we are
unhappy to see you well we could say
unhappy to see you well we could say
essentially here's here's what happens I
essentially here's here's what happens I
guess we should demonstrate this in the
guess we should demonstrate this in the
terminal before week before we do
terminal before week before we do
anything else so I'm gonna pull up
anything else so I'm gonna pull up
Python 3 and this is a nice thing
Python 3 and this is a nice thing
actually at first what I'm gonna do it's
actually at first what I'm gonna do it's
gonna clear my CLI and then I'm gonna
gonna clear my CLI and then I'm gonna
pull up Python 3 if you're ever curious
pull up Python 3 if you're ever curious
about using a function in Python this is
about using a function in Python this is
the downs this is the upside and being
the downs this is the upside and being
able to use it in an interpreter context
able to use it in an interpreter context
you can actually just fire up your
you can actually just fire up your
interpreter and just test variables test
interpreter and just test variables test
functions right away and I happen to
functions right away and I happen to
know that there's a function called dot
know that there's a function called dot
lower it works on strings but let's
lower it works on strings but let's
actually experiment with it so if I say
actually experiment with it so if I say
let's let's do for example the string
let's let's do for example the string
Colton and we'll say the lower
Colton and we'll say the lower
parentheses and we'll hit enter and
parentheses and we'll hit enter and
we'll see that indeed brings it all down
we'll see that indeed brings it all down
now this is weird why do you have a
now this is weird why do you have a
period after a string don't you need to
period after a string don't you need to
do with that on like a variable or
do with that on like a variable or
something so this is then this gets into
something so this is then this gets into
kind of the idea of what's called
kind of the idea of what's called
object-oriented programming which we
object-oriented programming which we
won't dive into today but essentially
won't dive into today but essentially
every string in Python has a series of
every string in Python has a series of
functions that it has its own reference
functions that it has its own reference
to and the function when you when you
to and the function when you when you
call it using this dot which essentially
call it using this dot which essentially
means go inside of the thing to the left
means go inside of the thing to the left
and then exit
and then exit
this thing that belongs to that thing on
this thing that belongs to that thing on
the left in this case the lower function
the left in this case the lower function
sort of belongs to this string Colton it
sort of belongs to this string Colton it
will run this function and sort of
will run this function and sort of
implicitly pass in this as a parameter
implicitly pass in this as a parameter
to this function yeah so what you really
to this function yeah so what you really
have is that Colton is indeed a string
have is that Colton is indeed a string
in this case in a string is an actual
in this case in a string is an actual
object I can create a class in Python so
object I can create a class in Python so
it has all of these phone bill tin to it
it has all of these phone bill tin to it
just one of which is this this lower
just one of which is this this lower
function so I see hasanul e proposed I
function so I see hasanul e proposed I
think what's actually a perfect solution
think what's actually a perfect solution
and that's a little simpler and less
and that's a little simpler and less
code to write than something like a list
code to write than something like a list
based approach so we want to deploy
based approach so we want to deploy
Hasan's approach sure so first before we
Hasan's approach sure so first before we
do that let's just test it again so we
do that let's just test it again so we
have the the version where it's my name
have the the version where it's my name
type normally let's type let's test it
type normally let's type let's test it
with the version of my name and all
with the version of my name and all
uppercase which does also go to the name
uppercase which does also go to the name
Colton and then just for just for kicks
Colton and then just for just for kicks
will do will do all my space style text
will do will do all my space style text
and then we'll show an area there we go
and then we'll show an area there we go
okay and then we'll see that no matter
okay and then we'll see that no matter
what permutation of capitalization we
what permutation of capitalization we
use we are unhappy to see you yes
use we are unhappy to see you yes
exactly
exactly
come with a better town to the same base
come with a better town to the same base
case so I'm gonna exit Python and then
case so I'm gonna exit Python and then
we'll adopt what was it Sean said which
we'll adopt what was it Sean said which
was if name
was if name
lower is equal to not not to Colton with
lower is equal to not not to Colton with
a capital C because that would that
a capital C because that would that
won't work there will never be any
won't work there will never be any
capital letters you're right alone I
capital letters you're right alone I
think well andrey caught it there but
think well andrey caught it there but
and I overstated we do have to make one
and I overstated we do have to make one
tweak which is just replace that with a
tweak which is just replace that with a
lowercase C indeed and if you run this
lowercase C indeed and if you run this
let's go back here and we'll do Python 3
let's go back here and we'll do Python 3
of hello dot pi again which I could have
of hello dot pi again which I could have
just hit up probably and we'll first
just hit up probably and we'll first
we'll try it with my name like this okay
we'll try it with my name like this okay
hello Colton it's a it's a frown okay so
hello Colton it's a it's a frown okay so
that was the behavior that was happening
that was the behavior that was happening
before let's try it again but this time
before let's try it again but this time
let's let's do just the first few couple
let's let's do just the first few couple
letters capitalized oh oh but here's the
letters capitalized oh oh but here's the
interesting thing is actually okay
interesting thing is actually okay
nevermind it's still printing out Co a
nevermind it's still printing out Co a
nice feature would be to have it print
nice feature would be to have it print
out the name with just a capital letter
out the name with just a capital letter
and not you should say cuz our next
and not you should say cuz our next
challenge is gonna be exactly that so
challenge is gonna be exactly that so
your user does miss type his or her name
your user does miss type his or her name
in some stupid way like Colton video
in some stupid way like Colton video
capital C capital o l3o in classic
capital C capital o l3o in classic
Colton we can at least with some
Colton we can at least with some
probability fix this in code now I say
probability fix this in code now I say
some probability because at least in
some probability because at least in
English there's a lot of names that have
English there's a lot of names that have
a mix of uppercase and lowercase
a mix of uppercase and lowercase
characters O'Reilly for instance is a
characters O'Reilly for instance is a
last name also the the name on a very
last name also the the name on a very
popular series of computer science books
popular series of computer science books
you might know so we could get this
you might know so we could get this
wrong but let's assume that we have very
wrong but let's assume that we have very
simple names in this case like Colton
simple names in this case like Colton
Capital Co how in Python could you force
Capital Co how in Python could you force
the users input to be neatened not all
the users input to be neatened not all
lowercase but capital C and then
lowercase but capital C and then
lowercase Olten well my first instinct
lowercase Olten well my first instinct
would be probably to use this named
would be probably to use this named
lower as our starting point well we'll
lower as our starting point well we'll
bring everything we'll canonicalize all
bring everything we'll canonicalize all
the names back to all lowercase like
the names back to all lowercase like
this and this actually let's actually
this and this actually let's actually
start with that so we'll go name dot
start with that so we'll go name dot
lower actually other way around well
lower actually other way around well
actually no will do in both cases we'll
actually no will do in both cases we'll
do in both cases so now you'll notice
do in both cases so now you'll notice
that I'm printing named lower in the
that I'm printing named lower in the
actual output for both situations and
actual output for both situations and
what we've typed into name so that way
what we've typed into name so that way
even if we type in capital C capital o
even if we type in capital C capital o
LTO n it's still gonna give us the
LTO n it's still gonna give us the
canonicalized
canonicalized
strings and not the best design but
strings and not the best design but
we'll get there well let's try this out
we'll get there well let's try this out
so we'll say this plays into your name
so we'll say this plays into your name
and we'll try Colton like that and it
and we'll try Colton like that and it
doesn't need say hello Colton with
doesn't need say hello Colton with
everything lowercase we're halfway there
everything lowercase we're halfway there
yeah I'm still have to now do the very
yeah I'm still have to now do the very
first string okay and the first
first string okay and the first
character and the first character in the
character and the first character in the
string so I actually offhand don't know
string so I actually offhand don't know
what function strings might have to
what function strings might have to
capitalize the first letter but the chat
capitalize the first letter but the chat
though so the chat happens but don't
though so the chat happens but don't
know looking at looking at how would you
know looking at looking at how would you
do this if you were home alone with that
do this if you were home alone with that
a live twitch stream to answer your
a live twitch stream to answer your
these questions for sure so I would
these questions for sure so I would
probably say Python capitalized first
probably say Python capitalized first
letter string so have the name of the
letter string so have the name of the
language is the first word cuz it's
language is the first word cuz it's
probably gonna be a major thing that
probably gonna be a major thing that
Google optimizes for and then just
Google optimizes for and then just
literally kind of the main words that I
literally kind of the main words that I
care about in the query for what I'm
care about in the query for what I'm
looking at which capitalized not you
looking at which capitalized not you
know we explore the first letter in a
know we explore the first letter in a
string yeah and this is something you
string yeah and this is something you
learn over time and odds are most
learn over time and odds are most
everyone in the chatroom is learning
everyone in the chatroom is learning
this already you don't have to ask
this already you don't have to ask
Google or Bing or whatever you use full
Google or Bing or whatever you use full
sentences you can drop the words that
sentences you can drop the words that
really aren't adding anything to the
really aren't adding anything to the
query like how and
query like how and
and it and is and really just focus on
and it and is and really just focus on
the words like Colton has here that
the words like Colton has here that
really have more information content for
really have more information content for
the research engine exactly somebody I'm
the research engine exactly somebody I'm
gonna do that query and the Google is
gonna do that query and the Google is
amazing the first result says in Python
amazing the first result says in Python
the capitalized method converts the
the capitalized method converts the
first character of a string to capital
first character of a string to capital
letter uppercase letter if the string
letter uppercase letter if the string
has its first character as a capital it
has its first character as a capital it
returns the original string yeah and I
returns the original string yeah and I
don't use this particular site too often
don't use this particular site too often
myself geeks for geeks or but it seems
myself geeks for geeks or but it seems
on point and just for kicks can you
on point and just for kicks can you
scroll down just so we can see what some
scroll down just so we can see what some
of the other search results are sure so
of the other search results are sure so
we're seeing stuck overflow is number
we're seeing stuck overflow is number
two stuck overflow is number three a
two stuck overflow is number three a
blog is number four programming program
blog is number four programming program
is calm is the next so you'll start to
is calm is the next so you'll start to
see patterns in search results if you're
see patterns in search results if you're
learning programming or teaching
learning programming or teaching
yourself Stack Overflow is a big one but
yourself Stack Overflow is a big one but
sometimes Google thinks that it's pretty
sometimes Google thinks that it's pretty
sure what it knows what the answer is so
sure what it knows what the answer is so
it'll just bubble it up special to the
it'll just bubble it up special to the
top oh all right so let's try this but
top oh all right so let's try this but
shout out to those of you in the chat
shout out to those of you in the chat
juban three and davis 216 all of whom
juban three and davis 216 all of whom
got this and major if thats if i'm
got this and major if thats if i'm
pronouncing that right also at a clever
pronouncing that right also at a clever
solution but arguably you're reinventing
solution but arguably you're reinventing
a wheel and i would propose that in
a wheel and i would propose that in
python you really try to reuse some of
python you really try to reuse some of
the wheels that have been given but odds
the wheels that have been given but odds
are underneath the hood capitalized is
are underneath the hood capitalized is
doing something quite like that but
doing something quite like that but
probably with some error checking just
probably with some error checking just
in case name is short indeed
in case name is short indeed
so we'll say name dot lower now this is
so we'll say name dot lower now this is
an interesting thing so when we call
an interesting thing so when we call
this method dot lower it's actually
this method dot lower it's actually
returning a string and new stream and
returning a string and new stream and
then that's essentially what we're doing
then that's essentially what we're doing
here we're returning a new string and
here we're returning a new string and
putting into the output we're returning
putting into the output we're returning
a new string and comparing it to the
a new string and comparing it to the
string colton so the cool thing is that
string colton so the cool thing is that
you can actually chain these methods
you can actually chain these methods
onto themselves so I can say name dot
onto themselves so I can say name dot
lower which gives me the name Colton in
lower which gives me the name Colton in
all lower case or whatever name and all
all lower case or whatever name and all
lower case letters but I can then do dot
lower case letters but I can then do dot
capitalize like so and what this will do
capitalize like so and what this will do
is this will say okay give me the thing
is this will say okay give me the thing
give me the dot lower method of the
give me the dot lower method of the
thing to the left okay and return it so
thing to the left okay and return it so
this will give whatever the name is all
this will give whatever the name is all
lower case letters and then this becomes
lower case letters and then this becomes
essentially that then when you call dot
essentially that then when you call dot
capital wise it's doing the same thing
capital wise it's doing the same thing
and saying give me the value to the left
and saying give me the value to the left
and then capitalize its first letter
and then capitalize its first letter
that thing to the left is now that lower
that thing to the left is now that lower
case
case
straight now when you hover over
straight now when you hover over
capitalise based on the definition of
capitalise based on the definition of
this function the BS code is feeding us
this function the BS code is feeding us
here do we need to force things to
here do we need to force things to
lowercase first and how would you go
lowercase first and how would you go
about figuring that out I returned a
about figuring that out I returned a
capitalized version of the string more
capitalized version of the string more
specifically make the first character
specifically make the first character
have uppercase and the rest lowercase ah
have uppercase and the rest lowercase ah
that's interesting I actually didn't
that's interesting I actually didn't
realize that that was part of the
realize that that was part of the
signature well let's try it then in that
signature well let's try it then in that
case so let's say if name dot capitalize
case so let's say if name dot capitalize
name capitalized and in this case I mean
name capitalized and in this case I mean
we could even we could even do it here
we could even we could even do it here
and just and say Colton and then dot
and just and say Colton and then dot
capitalized let's try it out so let's
capitalized let's try it out so let's
say the name of Colton first okay hello
say the name of Colton first okay hello
Colton let's try see Oh LTO n whoops
Colton let's try see Oh LTO n whoops
nice man look we have a whole new
nice man look we have a whole new
problem and how do we fix that problem
problem and how do we fix that problem
we get better at using the terminal oh
we get better at using the terminal oh
it turns out that that actually worked a
it turns out that that actually worked a
few steps ahead of us right and so
few steps ahead of us right and so
besides trial and error like we just did
besides trial and error like we just did
too you can certainly read the official
too you can certainly read the official
documentation in fact just so folks can
documentation in fact just so folks can
see it if you've never seen pythons
see it if you've never seen pythons
documentation it's so-so
documentation it's so-so
like all the and well most of the
like all the and well most of the
information is there but it's not always
information is there but it's not always
that easy to find what you're looking
that easy to find what you're looking
for dave is not a huge fan of the Python
for dave is not a huge fan of the Python
document so it could be much more
document so it could be much more
user-friendly so can you go ahead and
user-friendly so can you go ahead and
find us the documentation for the
find us the documentation for the
stiring classes capitalized function
stiring classes capitalized function
yeah so we'll go to STR which is the
yeah so we'll go to STR which is the
string class in Python a string object
string class in Python a string object
type and we went right here string
type and we went right here string
capitalized and it looks like it's
capitalized and it looks like it's
almost the important verbatim so yes
almost the important verbatim so yes
codes probably getting its instructions
codes probably getting its instructions
right from here but this is good that we
right from here but this is good that we
have the documentation up and notice how
have the documentation up and notice how
it's ordered you have on the Left
it's ordered you have on the Left
indented all of left aligned you have
indented all of left aligned you have
all of the function names in that class
all of the function names in that class
boldface no less capitalized case fold
boldface no less capitalized case fold
Center someone in the chat just a moment
Center someone in the chat just a moment
ago proposed title the title function is
ago proposed title the title function is
there a title function inside the string
there a title function inside the string
class let's go ahead and look if there's
class let's go ahead and look if there's
is title its string title yeah so this
is title its string title yeah so this
is title case version of the string or
is title case version of the string or
word start with an uppercase character
word start with an uppercase character
and the remaining characters are
and the remaining characters are
lowercase so this would be great for
lowercase so this would be great for
four full names yeah assuming no
four full names yeah assuming no
weirdness with like lowercase letters
weirdness with like lowercase letters
needing to be lowercase still sure but
needing to be lowercase still sure but
yeah absolutely
yeah absolutely
so we can maybe even experiment with
so we can maybe even experiment with
that so if I were to say let's go back
that so if I were to say let's go back
to the s code let's say it most
to the s code let's say it most
specifically maybe there's a Colton
specifically maybe there's a Colton
Jackson that we that we'd like to see
Jackson that we that we'd like to see
but Colton Ogden is the one we don't
but Colton Ogden is the one we don't
want to see so why don't we go ahead and
want to see so why don't we go ahead and
test that out so we'll say name title is
test that out so we'll say name title is
equal to because remember title doesn't
equal to because remember title doesn't
capitalized us but to multiple words in
capitalized us but to multiple words in
the string so in this case we don't have
the string so in this case we don't have
just one word we actually have two words
just one word we actually have two words
separated by its space so let's go ahead
separated by its space so let's go ahead
and say named title and name title and
and say named title and name title and
there is a better way to do this which
there is a better way to do this which
we should probably also take a look at
we should probably also take a look at
in just a second as well
in just a second as well
so we'll go ahead and run this code and
so we'll go ahead and run this code and
I'm gonna enter my name as Colton Ogden
I'm gonna enter my name as Colton Ogden
but all lowercase letters still don't
but all lowercase letters still don't
like them oh it looks like you figured
like them oh it looks like you figured
it out nice and actually smart
it out nice and actually smart
programming this is this artificial
programming this is this artificial
intelligence and this is the very this
intelligence and this is the very this
is the seed for artificial intelligence
is the seed for artificial intelligence
your six-line state-of-the-art you know
your six-line state-of-the-art you know
I would propose here too we are using on
I would propose here too we are using on
line three title to compare against
line three title to compare against
Colton Ogden capital C capital o yep I
Colton Ogden capital C capital o yep I
admit I don't love that maybe you can
admit I don't love that maybe you can
convince me otherwise it just feels
convince me otherwise it just feels
weird to not just choose something super
weird to not just choose something super
simple like all lowercase or all
simple like all lowercase or all
uppercase right because this assumes
uppercase right because this assumes
that now I have the sophistication or my
that now I have the sophistication or my
colleagues know what title does and
colleagues know what title does and
therefore this just seems a little more
therefore this just seems a little more
fragile would you agree or disagree I
fragile would you agree or disagree I
think I would large they agree I think I
think I would large they agree I think I
would say I think I would say what I
would say I think I would say what I
don't like the most is that we're using
don't like the most is that we're using
name title dot the dot title method
name title dot the dot title method
specifically in three places that for
specifically in three places that for
sure but I don't like title for
sure but I don't like title for
formatting but for for quality testing
formatting but for for quality testing
personally I would suggest you use
personally I would suggest you use
something that's absolutely robust all
something that's absolutely robust all
lowercase all uppercase or another
lowercase all uppercase or another
technique altogether but we'll get there
technique altogether but we'll get there
in just a moment again and another
in just a moment again and another
something good up my sleeve for you yeah
something good up my sleeve for you yeah
well dot lower lower probably be better
well dot lower lower probably be better
sorry so change that's what lower which
sorry so change that's what lower which
this - dot lower and then here's a nice
this - dot lower and then here's a nice
little shortcut if using vs code and
little shortcut if using vs code and
your highlight something let's say I
your highlight something let's say I
want to edit this and this whoops this
want to edit this and this whoops this
at the same time so I actually highlight
at the same time so I actually highlight
this and if I hit command D or control D
this and if I hit command D or control D
on a Windows computer I actually have
on a Windows computer I actually have
multiple cursors
multiple cursors
so now I can actually go over here and
so now I can actually go over here and
type lower amazing in two different
type lower amazing in two different
places it's typing twice as fast as I
places it's typing twice as fast as I
could have in my day there we go so
could have in my day there we go so
let's let's take things up a notch
let's let's take things up a notch
if we can because you know you have a
if we can because you know you have a
middle name right
middle name right
a lot of people have middle names and we
a lot of people have middle names and we
want to make sure that we want to be
want to make sure that we want to be
unhappy about all Colton Ogden's not
unhappy about all Colton Ogden's not
just you specifically so how could we go
just you specifically so how could we go
about adapting this program in such a
about adapting this program in such a
way then it is unhappy to see Colton
way then it is unhappy to see Colton
something Ogden or Colton something else
something Ogden or Colton something else
Ogden so that there's a Colton at the
Ogden so that there's a Colton at the
beginning and OGG and at the end we
beginning and OGG and at the end we
don't care what's in the middle but
don't care what's in the middle but
there can be something in the middle how
there can be something in the middle how
would you go about solving that problem
would you go about solving that problem
a middle name middle name yeah but one
a middle name middle name yeah but one
name two names
name two names
arbitrary number middle name I just
arbitrary number middle name I just
don't want to see any Colton's over here
don't want to see any Colton's over here
or Coggins over here okay sure so in
or Coggins over here okay sure so in
this case what we can probably do is
this case what we can probably do is
figure out well first of all we're gonna
figure out well first of all we're gonna
get input in a string of some kind and
get input in a string of some kind and
it's gonna be this presumably space
it's gonna be this presumably space
separated names no kind of sure so
separated names no kind of sure so
they're in Python a nice thing that you
they're in Python a nice thing that you
can do is you can actually do this thing
can do is you can actually do this thing
called split and split a string okay so
called split and split a string okay so
let's go into the end of the terminal
let's go into the end of the terminal
here and actually pull up the
here and actually pull up the
interpreter and you know I like this
interpreter and you know I like this
because you just want to play yeah
because you just want to play yeah
exactly
exactly
let's just get a sense of what the
let's just get a sense of what the
function looks like and so I'm indeed
function looks like and so I'm indeed
answered the questions in the chat yes
answered the questions in the chat yes
we're essentially at the moment just
we're essentially at the moment just
trying to get the first word in the last
trying to get the first word in the last
word yeah so we'll say let's say I have
word yeah so we'll say let's say I have
Colton Ogden here in a string and I want
Colton Ogden here in a string and I want
to split it into its constituents
to split it into its constituents
because so I'll just do thoughts split
because so I'll just do thoughts split
which is another method inside of the
which is another method inside of the
string class exactly and well we have
string class exactly and well we have
some interesting syntax here but it
some interesting syntax here but it
looks like it did find my first name and
looks like it did find my first name and
it separated out my last name and what
it separated out my last name and what
are these square brackets around you why
are these square brackets around you why
am i seeing that so these square
am i seeing that so these square
brackets are indicative of what you
brackets are indicative of what you
might have seen in java or c an array
might have seen in java or c an array
but in Python it's called a list and the
but in Python it's called a list and the
nice thing about lists and python is
nice thing about lists and python is
that they can be of arbitrary size they
that they can be of arbitrary size they
can grow dynamically you don't have to
can grow dynamically you don't have to
allocate memory for them if you're
allocate memory for them if you're
coming from a more statically based
coming from a more statically based
background yeah and I'm smiling because
background yeah and I'm smiling because
the sandwich in the chat here is
the sandwich in the chat here is
proposing that your sample middle name
proposing that your sample middle name
be Colton McLovin Ogden which is a great
be Colton McLovin Ogden which is a great
reference to a great movie question here
reference to a great movie question here
about can we use the in operator from
about can we use the in operator from
Richard because if the name is double
Richard because if the name is double
bare bare double barrelled that wouldn't
bare bare double barrelled that wouldn't
work so in just tests for the presence
work so in just tests for the presence
of a
of a
string anywhere and the string beginning
string anywhere and the string beginning
middle end or anywhere else in between
middle end or anywhere else in between
so it doesn't feel like the right fit we
so it doesn't feel like the right fit we
deliberately want to check the beginning
deliberately want to check the beginning
and the end so I think the road we're
and the end so I think the road we're
going down is at least one approach that
going down is at least one approach that
we can take yeah can someone who says
we can take yeah can someone who says
stir it up fine as well but again I
stir it up fine as well but again I
think that would also do lead us down
think that would also do lead us down
the same track something stir it up find
the same track something stir it up find
just literally finds whether and not a
just literally finds whether and not a
vision asks what if someone has to plus
vision asks what if someone has to plus
middle names that - we want to be
middle names that - we want to be
sensitive - so how it let's let's go
sensitive - so how it let's let's go
ahead and well I don't I don't just like
ahead and well I don't I don't just like
the approach you're taking just
the approach you're taking just
splitting on the strings but how do I go
splitting on the strings but how do I go
about checking for colton at the
about checking for colton at the
beginning in Ogden to the end and can we
beginning in Ogden to the end and can we
try and like mclovin and maybe a
try and like mclovin and maybe a
two-word middle name just to see what
two-word middle name just to see what
the result looks like yeah I know what
the result looks like yeah I know what
to code for so calling the glove and
to code for so calling the glove and
Hodgdon
Hodgdon
which is fantastic and actually you have
which is fantastic and actually you have
three you have a David J Malan as your
three you have a David J Malan as your
name we'll use that as well so let's
name we'll use that as well so let's
split that so again it worked just like
split that so again it worked just like
you did before even though we have three
you did before even though we have three
names instead of two it's split on
names instead of two it's split on
spaces
spaces
can I see four names that's this good
can I see four names that's this good
we'll see David J McLovin Mela nice
we'll see David J McLovin Mela nice
that's a mouthful and we'll split that
that's a mouthful and we'll split that
and okay so every string from the
and okay so every string from the
original string ends up inside of the
original string ends up inside of the
list it does so really we want to check
list it does so really we want to check
the beginning of the list and the end of
the beginning of the list and the end of
the list for Colton and Ogden and
the list for Colton and Ogden and
unhappiness we do and lists are nice in
unhappiness we do and lists are nice in
that you can just reference if you want
that you can just reference if you want
a specific spot in the list you can say
a specific spot in the list you can say
let's make a list here which has five
let's make a list here which has five
numbers in it well actually for
numbers in it well actually for
confusion let's not do that let's say I
confusion let's not do that let's say I
have apple orange and banana as a list
have apple orange and banana as a list
and we can have just use our names as
and we can have just use our names as
well but if I want to get a specific
well but if I want to get a specific
element from the list I can use what's
element from the list I can use what's
called an index and this is a numerical
called an index and this is a numerical
index so lists start their ordering of
index so lists start their ordering of
their elements at zero so for example in
their elements at zero so for example in
this case L at index zero is Apple and
this case L at index zero is Apple and
wise one if it's the first element cuz
wise one if it's the first element cuz
computer scientist
computer scientist
that zero is how they like to start
that zero is how they like to start
numbering things in a program three
numbering things in a program three
things you know what Lua is one indexed
things you know what Lua is one indexed
scratch just wounded next to yeah okay
scratch just wounded next to yeah okay
presumably for user-friendliness maybe
presumably for user-friendliness maybe
because Lua
because Lua
I know Lua was originally designed as a
I know Lua was originally designed as a
config language for less technical
config language for less technical
people and then scratch is a programming
people and then scratch is a programming
environment for people that are fresh to
environment for people that are fresh to
programming in computer science but
programming in computer science but
ironically it just ends up confusing
ironically it just ends up confusing
because then they eventually have to
because then they eventually have to
change yeah their transition to C or the
change yeah their transition to C or the
Java or whatever now what's this is zero
Java or whatever now what's this is zero
is that a number one on the left no
is that a number one on the left no
that's an L and L is just a shorthand in
that's an L and L is just a shorthand in
this case for a variable for list L for
this case for a variable for list L for
lips and you can this is typically
lips and you can this is typically
frowned upon you don't want to use a
frowned upon you don't want to use a
letter as a variable name for most
letter as a variable name for most
circumstances outside of maybe some
circumstances outside of maybe some
context we'll we'll get to a little bit
context we'll we'll get to a little bit
later but in this case I just wanted a
later but in this case I just wanted a
quick list so I'm gonna just use L again
quick list so I'm gonna just use L again
and what L looks like a one and a mono
and what L looks like a one and a mono
spaced font if I use these brackets just
spaced font if I use these brackets just
like we did for the actual to actually
like we did for the actual to actually
show the list itself but I say L at
show the list itself but I say L at
index zero this is how you can almost
index zero this is how you can almost
like almost like a box if we're thinking
like almost like a box if we're thinking
about it like there's little boxes
about it like there's little boxes
little cubbies for each individual spot
little cubbies for each individual spot
in our list
in our list
mm-hm if we do this we'll see that L at
mm-hm if we do this we'll see that L at
index zero returns Apple okay L at index
index zero returns Apple okay L at index
1 gives us orange I am and L at index 2
1 gives us orange I am and L at index 2
gives us banana so everything is
gives us banana so everything is
sequentially laid out and what fruit are
sequentially laid out and what fruit are
we gonna see it L bracket 3 ooh
we gonna see it L bracket 3 ooh
that's a good question it looks like
that's a good question it looks like
Python is smart enough to know at
Python is smart enough to know at
runtime whether or not we're actually
runtime whether or not we're actually
indexing outside of the rainbow we've
indexing outside of the rainbow we've
allocated for our list so in languages
allocated for our list so in languages
like C and C++ by default you're
like C and C++ by default you're
typically going to see no error but
typically going to see no error but
you're gonna be touching memory you
you're gonna be touching memory you
shouldn't or the program could even
shouldn't or the program could even
crash if you do something like this this
crash if you do something like this this
of course is an exception we'll talk
of course is an exception we'll talk
about that perhaps in another stream but
about that perhaps in another stream but
it's a way of handling errors and
it's a way of handling errors and
similarly what is l bracket negative 1
similarly what is l bracket negative 1
for instance can we go to the left oh
for instance can we go to the left oh
yeah solutely so L bracket negative 1
yeah solutely so L bracket negative 1
now this this would cause chaos I think
now this this would cause chaos I think
if you I'm really worried about this is
if you I'm really worried about this is
gonna break the computer Oh interesting
gonna break the computer Oh interesting
so Nana L negative one gave us it looks
so Nana L negative one gave us it looks
like banana the last element of our list
like banana the last element of our list
interesting now why is that well it
interesting now why is that well it
looks like it turns out that in Python
looks like it turns out that in Python
you actually get this nice little
you actually get this nice little
syntactic sugar for indexing into your
syntactic sugar for indexing into your
array from the
array from the
and not the head so to speak the end of
and not the head so to speak the end of
the list as opposed to the beginning and
the list as opposed to the beginning and
you know starting at negative one and
you know starting at negative one and
going and backwards negative two
going and backwards negative two
negative three you go from the end of
negative three you go from the end of
the list actually to the front of the
the list actually to the front of the
list of the head of the list so what's
list of the head of the list so what's
l-bracket negative to going to bell
l-bracket negative to going to bell
bracket negative 2 gives us orange which
bracket negative 2 gives us orange which
is again one further from the back of
is again one further from the back of
the list an L Bergen negative 3 o and
the list an L Bergen negative 3 o and
indeed all right so this is actually
indeed all right so this is actually
really handy when you want to do
really handy when you want to do
something relative to the end of the
something relative to the end of the
list but you don't want to have to do
list but you don't want to have to do
all of the math yourself necessarily you
all of the math yourself necessarily you
can just jump immediately to the end if
can just jump immediately to the end if
you know the index but the catch here is
you know the index but the catch here is
that I think when we go back to your
that I think when we go back to your
text editor we need to be robust against
text editor we need to be robust against
names with two words three words four
names with two words three words four
words so how can we go about modifying
words so how can we go about modifying
this program now in hello dot pi to
this program now in hello dot pi to
check that the first element in the list
check that the first element in the list
is Colton the last element is Alden but
is Colton the last element is Alden but
we don't really care how many other
we don't really care how many other
things are in between because I don't
things are in between because I don't
think we can hard code 0 + + 2 or 0 + 3
think we can hard code 0 + + 2 or 0 + 3
we need to figure out how many elements
we need to figure out how many elements
are in the list first right sure so our
are in the list first right sure so our
first step would be again to break the
first step would be again to break the
string up into its constituent parts
string up into its constituent parts
inside the split method so we can do
inside the split method so we can do
that here so we can say if well there's
that here so we can say if well there's
a few approaches we can do this we could
a few approaches we can do this we could
do names and actually take name dot
do names and actually take name dot
split nice and now we actually have
split nice and now we actually have
another variable not with the whole
another variable not with the whole
string but with the individual names
string but with the individual names
that make up the string that we passed
that make up the string that we passed
in okay nice so now what we can do is we
in okay nice so now what we can do is we
can say if names 0 because I remember
can say if names 0 because I remember
again if we're doing if we're indexing
again if we're doing if we're indexing
into our list at index 0 that's the very
into our list at index 0 that's the very
first element in our list and we want to
first element in our list and we want to
check to see if my first name if the
check to see if my first name if the
first name in the list that we've
first name in the list that we've
entered is Colton that's what we care
entered is Colton that's what we care
about so we'll just say if names 0
about so we'll just say if names 0
equals Colton and now here's the thing
equals Colton and now here's the thing
there are two conditions though because
there are two conditions though because
we could get a Colton Jackson a Colton
we could get a Colton Jackson a Colton
Smith or what-have-you but we care
Smith or what-have-you but we care
specifically about Colton Ogden you know
specifically about Colton Ogden you know
and so the others are delightful this is
and so the others are delightful this is
there are two actually two conditions
there are two actually two conditions
here that we care about not just one
here that we care about not just one
condition
condition
and the nice thing that Python lets you
and the nice thing that Python lets you
do is actually say okay if I want to
do is actually say okay if I want to
check for two different things I can
check for two different things I can
just say if something and
just say if something and
thing then do something if two things
thing then do something if two things
are true cut so you literally just say
are true cut so you literally just say
and you say and so I'll say if it's the
and you say and so I'll say if it's the
case that names zero is equal to the
case that names zero is equal to the
string Colton and names if I can type
string Colton and names if I can type
names at negative one again the last
names at negative one again the last
element in the list no matter the size
element in the list no matter the size
is equal to Ogden then we want to
is equal to Ogden then we want to
probably not say name dot lower probably
probably not say name dot lower probably
actually just say name dot well in this
actually just say name dot well in this
case we do name not capitalized name
case we do name not capitalized name
stuff what was it title I guess we can
stuff what was it title I guess we can
do name that title and then name that
do name that title and then name that
title again for the actual printing out
title again for the actual printing out
okay
okay
you know the other thing here though is
you know the other thing here though is
that if it's if in this case we
that if it's if in this case we
literally have the string Colton or
literally have the string Colton or
literally this chain table then it'll
literally this chain table then it'll
work but if we have if we've missed
work but if we have if we've missed
types like we talked about before it's
types like we talked about before it's
not gonna work yeah I don't like that so
not gonna work yeah I don't like that so
where should we do the lowercase trick
where should we do the lowercase trick
for instance like we did last time so
for instance like we did last time so
what we can do is I can say name dot
what we can do is I can say name dot
again lower and force everything to
again lower and force everything to
lowercase initially split exactly so
lowercase initially split exactly so
you'll get back a whole bunch of
you'll get back a whole bunch of
lowercase pieces now yeah this name even
lowercase pieces now yeah this name even
with the spaces all of the words all the
with the spaces all of the words all the
letters that are alphanumeric are
letters that are alphanumeric are
specifically alphabetical or going to be
specifically alphabetical or going to be
given a lower K they're lowercase
given a lower K they're lowercase
version okay and so then after that I
version okay and so then after that I
can change
can change
now we're not comparing for the
now we're not comparing for the
capitalized C we're actually comparing
capitalized C we're actually comparing
for the lowercase because everything's
for the lowercase because everything's
been canonicalized names okay it's then
been canonicalized names okay it's then
once we've done that now when we render
once we've done that now when we render
it when we actually display the name we
it when we actually display the name we
don't want to display a lowercase
don't want to display a lowercase
because then look that look weird in
because then look that look weird in
despite what they've typed it'll look
despite what they've typed it'll look
different we want to clean it up we want
different we want to clean it up we want
to give it the title aged version yeah
to give it the title aged version yeah
okay so let's actually try and run this
okay so let's actually try and run this
now assuming that I don't have any
now assuming that I don't have any
errors in here let me exit the
errors in here let me exit the
interpreter clear my screen and then run
interpreter clear my screen and then run
my hello dot pi so let's test it out
my hello dot pi so let's test it out
let's say David J Malan oh wow
let's say David J Malan oh wow
internationally and actually printed
internationally and actually printed
your name and it's happy to see you it
your name and it's happy to see you it
is which is good let's go ahead and tie
is which is good let's go ahead and tie
it let's try a Colton will use my actual
it let's try a Colton will use my actual
full name Colton Taylor Ogden
full name Colton Taylor Ogden
oh I'm happy to see you and happy to see
oh I'm happy to see you and happy to see
me what about Colton McLovin yeah what
me what about Colton McLovin yeah what
about coffee done Colton McLovin Ogden
about coffee done Colton McLovin Ogden
looks like it knows it's you Missy still
looks like it knows it's you Missy still
knows this mean I wouldn't
knows this mean I wouldn't
Colton was try Colton McLovin Smith he's
Colton was try Colton McLovin Smith he's
fine
fine
he's cool that's a different Colton what
he's cool that's a different Colton what
about just Colton okay let's try that
about just Colton okay let's try that
hello this was suggested in the chat if
hello this was suggested in the chat if
we just have one name oh it looks like
we just have one name oh it looks like
it's happy to see interesting cuz it
it's happy to see interesting cuz it
really is the Ogden that we don't like
really is the Ogden that we don't like
correct interest any Colton and
correct interest any Colton and
specifically if your string is one
specifically if your string is one
element long and you do negative 1 and 0
element long and you do negative 1 and 0
these are identical you get the same
these are identical you get the same
element because your your list is only
element because your your list is only
one size so from the bottom and from the
one size so from the bottom and from the
front it's making the same steps to get
front it's making the same steps to get
to the same value and I see Osley
to the same value and I see Osley
underscore t asks can you also do name 0
underscore t asks can you also do name 0
lower you can but then you're gonna end
lower you can but then you're gonna end
up calling lower in two places because
up calling lower in two places because
you're gonna do it on names bracket 0
you're gonna do it on names bracket 0
and names bracket negative 1 it's not
and names bracket negative 1 it's not
wrong it's just you're literally calling
wrong it's just you're literally calling
the function twice as many places as you
the function twice as many places as you
need to so I like what Colton did by
need to so I like what Colton did by
elevating it to this other temporary
elevating it to this other temporary
variable the pieces that end up in the
variable the pieces that end up in the
names variable as well this is where you
names variable as well this is where you
get points for star for design
get points for star for design
specifically would you bucket eyes this
specifically would you bucket eyes this
as design this would be designed right
as design this would be designed right
yeah this is design I would say style
yeah this is design I would say style
would be more about the indentation
would be more about the indentation
whether your variables are named
whether your variables are named
correctly but design is like the actual
correctly but design is like the actual
how you arrange your function calls and
how you arrange your function calls and
sort of mold your data to accomplish the
sort of mold your data to accomplish the
task at hand so I think if folks are
task at hand so I think if folks are
comfy I think there's a nice opportunity
comfy I think there's a nice opportunity
here even though the program is pretty
here even though the program is pretty
small to kind of take things to the next
small to kind of take things to the next
level and introduce a more advanced
level and introduce a more advanced
topic known as regular expressions okay
topic known as regular expressions okay
regular expressions allow you to check
regular expressions allow you to check
for patterns of user input which is nice
for patterns of user input which is nice
because what Colton's something
because what Colton's something
something Ogden really is it's a pattern
something Ogden really is it's a pattern
and we're being very deliberate right
and we're being very deliberate right
now in splitting the string on space
now in splitting the string on space
checking the first for Colton checking
checking the first for Colton checking
the last for Ogden but it turns out
the last for Ogden but it turns out
there's a general purpose tool by which
there's a general purpose tool by which
you can just do this by expressing
you can just do this by expressing
yourself in terms of a pattern and not
yourself in terms of a pattern and not
really getting into these lower level
really getting into these lower level
implementation details of splitting a
implementation details of splitting a
string and checking this and checking
string and checking this and checking
that would you mind walking us through
that would you mind walking us through
an alternative solution that uses
an alternative solution that uses
regular expressions instead of splits
regular expressions instead of splits
and these equality tests on the heels of
and these equality tests on the heels of
that Davis 216 says oh god not regular
that Davis 216 says oh god not regular
expressions oh here we go Davis these
expressions oh here we go Davis these
are great it's a great you're gonna
are great it's a great you're gonna
build them up for us step by step baby
build them up for us step by step baby
steps if you will so I know they didn't
steps if you will so I know they didn't
Python Python ships with a module called
Python Python ships with a module called
our e in a module in Python
our e in a module in Python
just a library that you have access to
just a library that you have access to
well specifically the module in Python
well specifically the module in Python
is a folder with a specific file in it
is a folder with a specific file in it
but modules as they're commonly known in
but modules as they're commonly known in
Python are just libraries that ship with
Python are just libraries that ship with
this the with the language itself part
this the with the language itself part
of the standard library so you can do
of the standard library so you can do
something at the very top of your
something at the very top of your
program like import re re being short
program like import re re being short
for of course regular expressions
for of course regular expressions
regular expression and I might have to
regular expression and I might have to
refresh my memory on how to actually use
refresh my memory on how to actually use
this library because it's a little while
this library because it's a little while
but this is what we have Google points
but this is what we have Google points
Mahlon but re a regular expression is
Mahlon but re a regular expression is
pretty cool it allows you to actually
pretty cool it allows you to actually
specify sort of a string pattern a
specify sort of a string pattern a
grammar so to speak for what you're
grammar so to speak for what you're
looking for what how you want to
looking for what how you want to
actually parse your string extract data
actually parse your string extract data
from it you know test whether it fits
from it you know test whether it fits
some kind of not hard-coded you know
some kind of not hard-coded you know
Colton Ogden but whether it's something
Colton Ogden but whether it's something
a little bit more complicated hmm
a little bit more complicated hmm
so in this case so what do we how do we
so in this case so what do we how do we
want to do this we want to use re just a
want to do this we want to use re just a
test for Colton Ogden or I want a Colton
test for Colton Ogden or I want a Colton
at the beginning and Ogden at the end
at the beginning and Ogden at the end
and I'll take anything in between and I
and I'll take anything in between and I
don't care about capitalization I go
don't care about capitalization I go
away
away
okay sure now we should note there's a
okay sure now we should note there's a
few there's a little bit of nervousness
few there's a little bit of nervousness
in the chat and that's fine and I do
in the chat and that's fine and I do
think you'll find that once we introduce
think you'll find that once we introduce
this sort of piecewise a little bit by
this sort of piecewise a little bit by
little bit honestly you'll found these
little bit honestly you'll found these
pretty straightforward and pretty
pretty straightforward and pretty
powerful with that said sometimes they
powerful with that said sometimes they
get crazy complicated and literally a
get crazy complicated and literally a
day or two ago that I email a colleague
day or two ago that I email a colleague
saying hey how do i express this in a
saying hey how do i express this in a
regular expression because even I get
regular expression because even I get
rusty on it sometimes but we're gonna
rusty on it sometimes but we're gonna
take it slow and make this pretty pretty
take it slow and make this pretty pretty
compelling yeah you said there's
compelling yeah you said there's
nervousness in the chat a little
nervousness in the chat a little
nervousness here in person oh I'm gonna
nervousness here in person oh I'm gonna
I'll be honest with you but we'll figure
I'll be honest with you but we'll figure
it out it's okay this is a judgment-free
it out it's okay this is a judgment-free
zone over here notice so there are a few
zone over here notice so there are a few
functions that I know that exists in our
functions that I know that exists in our
e and you can do what's called compiling
e and you can do what's called compiling
regular expression where you actually
regular expression where you actually
create an object that takes in a regular
create an object that takes in a regular
expression string and sort of creates an
expression string and sort of creates an
object that you can then use to do
object that you can then use to do
matches more efficiently down the line
matches more efficiently down the line
alternatively you can do something
alternatively you can do something
called re match which doesn't take a
called re match which doesn't take a
compiled regular expression but just
compiled regular expression but just
kind of does it on
kind of does it on
little bit more on the fly this is based
little bit more on the fly this is based
on my memory it can be wrong we'll find
on my memory it can be wrong we'll find
out very shortly so if I say so right
out very shortly so if I say so right
now we're getting the the name so please
now we're getting the the name so please
into your name and you know regular
into your name and you know regular
persons are nice in that you actually
persons are nice in that you actually
don't need to test forgot lower in this
don't need to test forgot lower in this
case you know you can express that
case you know you can express that
different like yeah you can you can use
different like yeah you can you can use
a regular expression actually to say hey
a regular expression actually to say hey
regardless of case is this match Colton
regardless of case is this match Colton
Ogden so actually I'm gonna get rid of
Ogden so actually I'm gonna get rid of
this dot lower I'm actually gonna get
this dot lower I'm actually gonna get
rid of split and I actually gonna get
rid of split and I actually gonna get
rid of names altogether because I'm not
rid of names altogether because I'm not
gonna need a list and I'm actually gonna
gonna need a list and I'm actually gonna
get rid of this if state this is what's
get rid of this if state this is what's
getting cool I mean I know there's some
getting cool I mean I know there's some
nerves there but this program is gonna
nerves there but this program is gonna
actually end up being shorter using a
actually end up being shorter using a
regular expression now I'm gonna start
regular expression now I'm gonna start
using our this function called re-match
using our this function called re-match
okay and it looks like this we'll try to
okay and it looks like this we'll try to
apply the pattern at the start of
apply the pattern at the start of
whatever string we pass into it so it's
whatever string we pass into it so it's
gonna take a pattern and re patter regex
gonna take a pattern and re patter regex
pattern rejecting stuff rate of
pattern rejecting stuff rate of
expressions so I'm gonna say if re match
expressions so I'm gonna say if re match
and I'm gonna use this an R string which
and I'm gonna use this an R string which
is just a regular expression string and
is just a regular expression string and
actually will serve raw string broccoli
actually will serve raw string broccoli
and it will format it a little bit
and it will format it a little bit
differently electric show you things a
differently electric show you things a
little bit differently and now I'm a
little bit differently and now I'm a
little rusty with my zip with my regular
little rusty with my zip with my regular
expressions today oh but I want to
expressions today oh but I want to
basically do C or C and then Oulton
basically do C or C and then Oulton
space actually and I think I might be
space actually and I think I might be
misremembering space it's either that or
misremembering space it's either that or
that I think one of the two is the
that I think one of the two is the
opposite there's some deep breathing in
opposite there's some deep breathing in
the chat but if you're in the chat you
the chat but if you're in the chat you
know a little bit about regular
know a little bit about regular
expressions by all means chime in here
expressions by all means chime in here
and paste your ideas you can do this in
and paste your ideas you can do this in
bunches of different ways and we'll give
bunches of different ways and we'll give
you one or more along the way here so
you one or more along the way here so
and then what we want to do actually is
and then what we want to do actually is
say plus for an arbitrary number of
say plus for an arbitrary number of
spaces now this might not be the correct
spaces now this might not be the correct
character I'm going to I'm gonna try it
character I'm going to I'm gonna try it
here so let's let's just run it and then
here so let's let's just run it and then
if this is wrong we will we'll do a
if this is wrong we will we'll do a
little bit of it well do a little bit of
little bit of it well do a little bit of
googling and oh I forgot you can see it
googling and oh I forgot you can see it
when I make faces at the camera there
when I make faces at the camera there
right
right
we'll go to a website that I like called
we'll go to a website that I like called
regex pal okay so please enter your name
regex pal okay so please enter your name
let's say Colton Ogden Oh missing one
let's say Colton Ogden Oh missing one
required position oh okay we have to
required position oh okay we have to
actually do it on the string itself so
actually do it on the string itself so
we need to say Nate okay let's try it so
we need to say Nate okay let's try it so
you're gonna match this pattern right
you're gonna match this pattern right
left against this variable on the right
left against this variable on the right
right correct and that's do that so say
right correct and that's do that so say
enter my name Colton Ogden oh it's I'm
enter my name Colton Ogden oh it's I'm
happy to see you it worked
happy to see you it worked
okay well let's make sure let's make
okay well let's make sure let's make
sure that it actually still works for
sure that it actually still works for
other use cases let's say Colton Taylor
other use cases let's say Colton Taylor
Ogden oh it's happy to see Colton Taylor
Ogden oh it's happy to see Colton Taylor
on me you know what I'm realizing is
on me you know what I'm realizing is
that with all we did was we just said
that with all we did was we just said
check for an arbitrary number of spaces
check for an arbitrary number of spaces
not four characters other characters hmm
not four characters other characters hmm
so that's kind of that is kind of a
so that's kind of that is kind of a
problem so what I probably want to do is
problem so what I probably want to do is
say how do we do this I guess we can
say how do we do this I guess we can
just use dot plus okay and then dot
just use dot plus okay and then dot
essentially means any character and
essentially means any character and
we'll see we'll see if that works let's
we'll see we'll see if that works let's
try that out
try that out
so we'll say Colton Taylor Ogden oh it
so we'll say Colton Taylor Ogden oh it
looks like it's working now intro okay
looks like it's working now intro okay
but what if we do what if we okay let's
but what if we do what if we okay let's
try David J Malin oh it is happy to see
try David J Malin oh it is happy to see
you okay interests did I mess up is
you okay interests did I mess up is
there well what about a four person name
there well what about a four person name
okay let's try it so let's say call it
okay let's try it so let's say call it
up PI Colton Mik love and Taylor Ogden
up PI Colton Mik love and Taylor Ogden
looks like it's indeed unhappy to see me
looks like it's indeed unhappy to see me
still it knows it's babe how about
still it knows it's babe how about
Colton osku P Ogden
Colton osku P Ogden
oh yeah that's gonna be a problem isn't
oh yeah that's gonna be a problem isn't
it okay okay
it okay okay
Colton on CPR game but see the thing is
Colton on CPR game but see the thing is
people know that that's me still yeah
people know that that's me still yeah
but I wanted Colton at the beginning and
but I wanted Colton at the beginning and
Ogden at the end not on colonoscopy so
Ogden at the end not on colonoscopy so
there's a bug here right it's being a
there's a bug here right it's being a
little too generous and it's looking
little too generous and it's looking
apparently for CEO ltn and then anything
apparently for CEO ltn and then anything
else but I want there to be a space
else but I want there to be a space
there so what I want to do is I want to
there so what I want to do is I want to
have at least one space and then an
have at least one space and then an
arbitrary number of care okay backslash
arbitrary number of care okay backslash
backslash s means any space so like
backslash s means any space so like
space bar tab other things too so let's
space bar tab other things too so let's
try that so we'll go here we'll try my
try that so we'll go here we'll try my
name as
name as
Wilton Taylor Ogden which is unhappy to
Wilton Taylor Ogden which is unhappy to
see me and then Colton ah Skippy done
see me and then Colton ah Skippy done
and it's still happy to see me
and it's still happy to see me
okay what is okay I got a little bit
okay what is okay I got a little bit
what about let's try one more
what about let's try one more
how about Colton Colton MOG then all
how about Colton Colton MOG then all
right I do need to have a space before
right I do need to have a space before
that Oh as well okay
that Oh as well okay
um seeing a Hilton mugged and I'm cool
um seeing a Hilton mugged and I'm cool
with that's my soda
with that's my soda
you win a happy face okay so what we
you win a happy face okay so what we
need to do that is to again there's
need to do that is to again there's
there should be a space before the oh
there should be a space before the oh
and I guess I should have explained
and I guess I should have explained
before to here this C bar C just means
before to here this C bar C just means
one of the other that bar just music an
one of the other that bar just music an
or and I'm gonna need to correct you on
or and I'm gonna need to correct you on
that though before long we can I have to
that though before long we can I have to
do that now or come back to you're gonna
do that now or come back to you're gonna
die now let's go alright so if I can
die now let's go alright so if I can
just interject with some some my elder
just interject with some some my elder
wisdom here
wisdom here
so the grab the square brackets here and
so the grab the square brackets here and
here denote what's called a character
here denote what's called a character
class in the regular expression and that
class in the regular expression and that
is a set of one or more characters that
is a set of one or more characters that
you want to treat either of so in this
you want to treat either of so in this
case the vertical bar unfortunately is
case the vertical bar unfortunately is
not necessary because this expression
not necessary because this expression
where we literally give you a capital C
where we literally give you a capital C
or a C that's indeed the role of a carry
or a C that's indeed the role of a carry
well if we did it this way we'd want the
well if we did it this way we'd want the
bar right yes but then parentheses
bar right yes but then parentheses
around it so that it's C or little C
around it so that it's C or little C
like that exactly so that would work as
like that exactly so that would work as
well but I think we should fix it for
well but I think we should fix it for
the Ogden as well and the end all right
the Ogden as well and the end all right
we'll do it like that and then we'll do
we'll do it like that and then we'll do
it like that I like that now but I think
it like that I like that now but I think
person folks in the chat here we're
person folks in the chat here we're
trying to handle some number of names in
trying to handle some number of names in
between Colton and Ogden so the pattern
between Colton and Ogden so the pattern
really is Colton one or more spaces
really is Colton one or more spaces
maybe one or more other words then maybe
maybe one or more other words then maybe
a space than Ogden so it's getting a
a space than Ogden so it's getting a
little complicated now and I can
little complicated now and I can
appreciate this is where some of the
appreciate this is where some of the
pain goes so oh my god we didn't also
pain goes so oh my god we didn't also
cover the the carrot and the dollar sign
cover the the carrot and the dollar sign
no we can now stall and go to those now
no we can now stall and go to those now
instead if you want yeah those are the
instead if you want yeah those are the
probably the easiest part of the whole
probably the easiest part of the whole
folk a so the carrot just means the
folk a so the carrot just means the
string has to start with this okay and
string has to start with this okay and
the dollar sign means the string has to
the dollar sign means the string has to
end with this
end with this
that's true in Connect can i interject
that's true in Connect can i interject
with my uh my older way don't have the
with my uh my older way don't have the
carrot symbol confusingly is not
carrot symbol confusingly is not
necessary here because the match
necessary here because the match
function in python takes is a check from
function in python takes is a check from
the beginning but so let me propose this
the beginning but so let me propose this
let's use our e dot search which is
let's use our e dot search which is
slightly more general purpose and don't
slightly more general purpose and don't
worry about getting hung up on those
worry about getting hung up on those
details for efficiency reasons they can
details for efficiency reasons they can
actually be a good thing but in this
actually be a good thing but in this
case here now we have a general purpose
case here now we have a general purpose
tool the carrot says start the string
tool the carrot says start the string
the dollar sign says end of the string
the dollar sign says end of the string
and now we just need to get everything
and now we just need to get everything
right in between Colton's hair says I
right in between Colton's hair says I
thought I wouldn't have a headache today
thought I wouldn't have a headache today
but here we go thanks Dave okay but
but here we go thanks Dave okay but
again notice what we're doing we're
again notice what we're doing we're
taking baby steps toward getting it
taking baby steps toward getting it
right a little more right a little more
right a little more right a little more
right and then hopefully a hundred
right and then hopefully a hundred
percent right so what we need to express
percent right so what we need to express
in the middle it seems is optionally a
in the middle it seems is optionally a
word and a space again and again and
word and a space again and again and
again and again so how could we do that
again and again so how could we do that
for folks so if we do so essentially
for folks so if we do so essentially
replace this dot plus yeah that feels a
replace this dot plus yeah that feels a
little too luxe cuz da in this case is
little too luxe cuz da in this case is
not a period it means any character I
not a period it means any character I
don't want to do a period we would have
don't want to do a period we would have
to actually backslash escape it exactly
to actually backslash escape it exactly
but that's even worse so let's not do
but that's even worse so let's not do
that okay so we know that we're gonna
that okay so we know that we're gonna
have a space then we're gonna have a
have a space then we're gonna have a
after the Colton and then a space before
after the Colton and then a space before
they Ogden and in between that and
they Ogden and in between that and
arbitrary range of words so I'm going to
arbitrary range of words so I'm going to
say we'll do eight well in this case
say we'll do eight well in this case
also an arbitrary an arbitrary number of
also an arbitrary an arbitrary number of
spaces as well if we want to accommodate
spaces as well if we want to accommodate
possibilities okay and so we'll say if
possibilities okay and so we'll say if
we're not gonna use the dot essentially
we're not gonna use the dot essentially
the wild-card thing we want to
the wild-card thing we want to
accommodate that I'm presumably now what
accommodate that I'm presumably now what
you talked about before with character
you talked about before with character
classes we can actually specify a range
classes we can actually specify a range
of characters using this syntax where we
of characters using this syntax where we
say A to Z capital A to Z lower case
say A to Z capital A to Z lower case
zero to nine which means all numbers and
zero to nine which means all numbers and
this just means all characters from A to
this just means all characters from A to
Z capitalized all and all characters
Z capitalized all and all characters
from A to Z lowercase and all digits
from A to Z lowercase and all digits
from 0 to 9 and I'm guessing that's
from 0 to 9 and I'm guessing that's
probably even a simpler way to do this
probably even a simpler way to do this
with the - W / W would be a word
with the - W / W would be a word
character so it would give you the
character so it would give you the
letters of the alphabet in that case
letters of the alphabet in that case
would we want to do something like you
would we want to do something like you
know I'm okay with using dot to just
know I'm okay with using dot to just
represent any care
represent any care
just cuz I think that'll keep it simpler
just cuz I think that'll keep it simpler
but we can make it more precise if you
but we can make it more precise if you
want okay but so dot something so it's
want okay but so dot something so it's
OB director bus and then a space and
OB director bus and then a space and
then this whole thing really should well
then this whole thing really should well
I guess it would go when it go into
I guess it would go when it go into
square bracket so that actually hundreds
square bracket so that actually hundreds
I think you probably what parentheses
I think you probably what parentheses
okay because you can use parentheses for
okay because you can use parentheses for
grouping you use square brackets for
grouping you use square brackets for
character classes a finite number of
character classes a finite number of
characters that you want to expect and
characters that you want to expect and
then with then this itself or no and
then with then this itself or no and
then a space and then and then this in a
then a space and then and then this in a
bracket and then that with a plus oh
bracket and then that with a plus oh
actually this not that okay and I let me
actually this not that okay and I let me
propose we can simplify get rid of all
propose we can simplify get rid of all
the brackets in the middle there they're
the brackets in the middle there they're
just not necessary
just not necessary
okay so what I'm seeing here is this if
okay so what I'm seeing here is this if
I can read this from left to right we
I can read this from left to right we
want start of the string then give me a
want start of the string then give me a
capital C or a lowercase C right then
capital C or a lowercase C right then
give me Oh
give me Oh
LTO n then give me one or more spaces
LTO n then give me one or more spaces
right so even if you're getting a little
right so even if you're getting a little
overwhelmed right now just take a step
overwhelmed right now just take a step
back and consider okay I understand like
back and consider okay I understand like
the first third of the regular
the first third of the regular
expression so now we're saying in
expression so now we're saying in
parentheses the following group give me
parentheses the following group give me
any character one or more times followed
any character one or more times followed
by a space and I like that and then
by a space and I like that and then
you're saying here with the plus
you're saying here with the plus
whatever I just had in parenthesis allow
whatever I just had in parenthesis allow
me one or more of those but you're
me one or more of those but you're
currently therefore requiring a middle
currently therefore requiring a middle
name because plus means one or more of
name because plus means one or more of
the things so how can you say zero or
the things so how can you say zero or
more of those things
more of those things
Oh actually offhand I don't know we
Oh actually offhand I don't know we
might have to consult Google for this
might have to consult Google for this
okay so regex 0 or more reasonable
okay so regex 0 or more reasonable
search query okay 0 or 1 oh this is 0 or
search query okay 0 or 1 oh this is 0 or
1 it's not we're not going so sometimes
1 it's not we're not going so sometimes
the first hit is not the best thanks
the first hit is not the best thanks
google okay let's try this so wrong
google okay let's try this so wrong
language but it's probably gonna be
language but it's probably gonna be
relevant because languages tend to use
relevant because languages tend to use
the same syntax for regular expressions
the same syntax for regular expressions
okay I'm agitated okay no that's that's
okay I'm agitated okay no that's that's
for a range let's see 0 okay here's 0 or
for a range let's see 0 okay here's 0 or
100 here's okay star is 0 or more
100 here's okay star is 0 or more
okay so that effectively makes it
okay so that effectively makes it
optional some number of times so then we
optional some number of times so then we
don't need this Plus anymore we instead
don't need this Plus anymore we instead
want this star correct and now the only
want this star correct and now the only
thing I would be a little careful of is
thing I would be a little careful of is
this strictly speaking we could have
this strictly speaking we could have
that there but I don't think we need it
that there but I don't think we need it
because if we instead just say give me
because if we instead just say give me
one or more spaces after the optional
one or more spaces after the optional
middle name that should offset it from
middle name that should offset it from
your last name right so if we recap and
your last name right so if we recap and
this is what I would do when making my
this is what I would do when making my
own regular expressions because honestly
own regular expressions because honestly
it's getting confusing so you want to
it's getting confusing so you want to
just break it down again
just break it down again
so this says start at the beginning then
so this says start at the beginning then
give me a capital C or a lowercase C
give me a capital C or a lowercase C
then an O LT o n then go ahead and give
then an O LT o n then go ahead and give
me one or more spaces to separate it
me one or more spaces to separate it
from everything else right then go ahead
from everything else right then go ahead
and give me optionally zero or more
and give me optionally zero or more
times the following stuff the following
times the following stuff the following
stuff is any character one or more times
stuff is any character one or more times
followed by one space or more spaces but
followed by one space or more spaces but
that whole thing is optional so what the
that whole thing is optional so what the
parenthesized expression really
parenthesized expression really
represents is optional middle name
represents is optional middle name
middle name middle name middle name and
middle name middle name middle name and
it repeats and someone commented in the
it repeats and someone commented in the
chat earlier about your theory class
chat earlier about your theory class
being germane if you've ever written
being germane if you've ever written
drawn out on a whiteboard or a piece of
drawn out on a whiteboard or a piece of
paper DFA a deterministic finite
paper DFA a deterministic finite
automaton or an N DFA a
automaton or an N DFA a
non-deterministic find out to Thomas on
non-deterministic find out to Thomas on
the picture you're drawing that has
the picture you're drawing that has
loops like this that is what the star is
loops like this that is what the star is
doing give me one or more of these again
doing give me one or more of these again
and again now that if you've thought if
and again now that if you've thought if
you follow that okay then at the very
you follow that okay then at the very
end we just have some Ogden so that
end we just have some Ogden so that
means give me a capital o or a lowercase
means give me a capital o or a lowercase
O then a GD en end of string so again
O then a GD en end of string so again
crazy complex when you look at it at
crazy complex when you look at it at
first glance but break it down into
first glance but break it down into
those constituent parts and I think
those constituent parts and I think
it'll it'll pop for you as well let's s
it'll it'll pop for you as well let's s
that's actually make sure it works
that's actually make sure it works
so we'll say hello pop quiz it's your
so we'll say hello pop quiz it's your
name Colton Taylor Ogden okay
name Colton Taylor Ogden okay
looks a it works alright always
looks a it works alright always
satisfying we spend all that time a
satisfying we spend all that time a
little nervous I don't think we should
little nervous I don't think we should
test anymore there J Malin nice to see
test anymore there J Malin nice to see
you okay let's try let's try and
you okay let's try let's try and
situation where I just have no middle
situation where I just have no middle
name okay so wise okay and then if we
name okay so wise okay and then if we
try let's let's say we try four names so
try let's let's say we try four names so
make up love and
make up love and
Taylor Hagen looks like it still
Taylor Hagen looks like it still
recognizes this
recognizes this
so what Colin's doing here is an example
so what Colin's doing here is an example
of course just manually testing his code
of course just manually testing his code
trying a bunch of inputs once you get
trying a bunch of inputs once you get
more comfortable programming can you use
more comfortable programming can you use
various tools to automate this testing
various tools to automate this testing
so Colton or someone would still have to
so Colton or someone would still have to
think about all of those different
think about all of those different
examples but you'd save the tests in
examples but you'd save the tests in
another file and then run some automated
another file and then run some automated
process that would constantly run those
process that would constantly run those
sample inputs against your program to
sample inputs against your program to
make sure that you haven't messed up and
make sure that you haven't messed up and
created a new problem Oh someone
created a new problem Oh someone
actually says try only Colton
actually says try only Colton
oh come a little nervous okay Cole
oh come a little nervous okay Cole
please cool because we don't know if
please cool because we don't know if
it's the one we don't like what about
it's the one we don't like what about
though Colton odd then in all caps if
though Colton odd then in all caps if
you could someone who's yelling they're
you could someone who's yelling they're
really just they're yelling your name
really just they're yelling your name
there we go Colton Hogg then we didn't
there we go Colton Hogg then we didn't
we didn't come back we didn't account
we didn't come back we didn't account
for that oh we know we did it no I am
for that oh we know we did it no I am
not pleased to see that Colton Ogden
not pleased to see that Colton Ogden
either so how do we fix that yeah so
either so how do we fix that yeah so
here's the thing what we want to do is
here's the thing what we want to do is
get back into lower casing things we
get back into lower casing things we
want to go to name dot we could do that
want to go to name dot we could do that
way or I think you've read the my face
way or I think you've read the my face
there yeah I'm pretty sure we can do
there yeah I'm pretty sure we can do
this with regular expressions though we
this with regular expressions though we
probably could so we could just do the
probably could so we could just do the
same thing that we did before which is
same thing that we did before which is
not that we do I guess it might be font
not that we do I guess it might be font
oh because I haven't string highlighted
oh because I haven't string highlighted
that's why so if I go over here do and
that's why so if I go over here do and
oh oh you could just have a whole bunch
oh oh you could just have a whole bunch
of characters one for each letter
of characters one for each letter
there's probably a more efficient way to
there's probably a more efficient way to
but dear god this looks scary
but dear god this looks scary
it's kind of cool though too that your
it's kind of cool though too that your
name is like duplicated this way yeah so
name is like duplicated this way yeah so
you could do this this is correct but I
you could do this this is correct but I
would argue bad design why because one
would argue bad design why because one
it's just so damn hard to read now it's
it's just so damn hard to read now it's
just making this string so much longer
just making this string so much longer
and we're not even done with the Ogden
and we're not even done with the Ogden
yet so I would propose undo all that and
yet so I would propose undo all that and
it turns out there's a way with our
it turns out there's a way with our
research and also for that other
research and also for that other
function re-match to tell them to match
function re-match to tell them to match
your pattern case-insensitive lee so how
your pattern case-insensitive lee so how
would you go if I told you is like your
would you go if I told you is like your
tutor like this is possible how do you
tutor like this is possible how do you
go about solving a problem like that now
go about solving a problem like that now
on your own okay so I would go into
on your own okay so I would go into
Google and I would say okay our
Google and I would say okay our
professor Google search case-insensitive
professor Google search case-insensitive
without re compilers we're not using re
without re compilers we're not using re
compiles a stack that will another day
compiles a stack that will another day
Stack Overflow is an awesome resources
Stack Overflow is an awesome resources
and it looks like it says pass our
and it looks like it says pass our
ignore case in all capital letters to
ignore case in all capital letters to
the flags parameter of search match or
the flags parameter of search match or
sub now what is this Flags parameter how
sub now what is this Flags parameter how
do I look that up so if we go over to
do I look that up so if we go over to
the documentation actually I think we
the documentation actually I think we
need to have the documentation time open
need to have the documentation time open
over here already scroll the very top
over here already scroll the very top
Gera this type in read do that go into
Gera this type in read do that go into
the module for re which is our the
the module for re which is our the
module we imported and then I'm gonna
module we imported and then I'm gonna
specifically I'm using the search
specifically I'm using the search
function so I'm actually gonna type
function so I'm actually gonna type
research and let's go to where it's
research and let's go to where it's
actually defined so it looks like it's
actually defined so it looks like it's
defined right here so it does say we
defined right here so it does say we
have a pattern as the first parameter
have a pattern as the first parameter
we've talked about this string that we
we've talked about this string that we
actually want to search inside of us the
actually want to search inside of us the
second parameter and then this Flags
second parameter and then this Flags
equals zero
equals zero
which is interesting because we're not
which is interesting because we're not
passing in a number at least not that we
passing in a number at least not that we
can see when we're doing it presumably
can see when we're doing it presumably
you're not but the equals zero means
you're not but the equals zero means
that that argument called Flags has a
that that argument called Flags has a
default value of zero no matter why you
default value of zero no matter why you
so you don't have to provide it and and
so you don't have to provide it and and
truly underneath the hood all of the re
truly underneath the hood all of the re
dot capital words that we could pass
dot capital words that we could pass
into it are actually numerical and they
into it are actually numerical and they
form what's called a mask or a bit mask
form what's called a mask or a bit mask
a sort of a sequence of powers of two
a sort of a sequence of powers of two
added together in some arbitrary way to
added together in some arbitrary way to
set a series of flags and one compact
set a series of flags and one compact
piece of information mm-hmm
piece of information mm-hmm
and in here says where does it say
and in here says where does it say
doesn't like it actually has any
doesn't like it actually has any
information on flags itself not that
information on flags itself not that
part of the documentation but it's in
part of the documentation but it's in
there we go to Flags oh you just yep
there we go to Flags oh you just yep
you hide it on the screen a moment ago I
you hide it on the screen a moment ago I
did that I saw re multi-line re dot
did that I saw re multi-line re dot
multi there we go oh here are the flags
multi there we go oh here are the flags
okay it looks like they kind of have it
okay it looks like they kind of have it
separately from everything else so these
separately from everything else so these
are some of the flags so actually some
are some of the flags so actually some
of these flags or some of these just
of these flags or some of these just
completely other variables
completely other variables
no these the capitalized ones are all
no these the capitalized ones are all
flags and that I don't know how to
flags and that I don't know how to
pronounce this one but the van
pronounce this one but the van
it's proposed adding the flags ignore
it's proposed adding the flags ignore
case and that's spot on
case and that's spot on
yeah in this case are ignore case more
yeah in this case are ignore case more
specifically this we wanted to import
specifically this we wanted to import
star from re mmm-hmm indeed so let's go
star from re mmm-hmm indeed so let's go
back to well actually I don't know if
back to well actually I don't know if
you wanted to talk more about what they
you wanted to talk more about what they
are but essentially ignore case there's
are but essentially ignore case there's
multi line which will let you test
multi line which will let you test
regular expressions at span lines and
regular expressions at span lines and
then there's ignore case which will
then there's ignore case which will
perform case insensitive matching
perform case insensitive matching
expressions like a-to-z nice like we
expressions like a-to-z nice like we
lived up so we can just disable the
lived up so we can just disable the
notion of case all together without
notion of case all together without
having to manually force things match
having to manually force things match
lower case those actually that means
lower case those actually that means
that we can get rid of this we can
that we can get rid of this we can
actually just say nice Colton like that
actually just say nice Colton like that
yeah and then Ogden and then as our last
yeah and then Ogden and then as our last
parameter to our readout search we can
parameter to our readout search we can
say re dot ignore cases yeah so it's a
say re dot ignore cases yeah so it's a
third argument now explicit so that's
third argument now explicit so that's
gonna tell our research don't even worry
gonna tell our research don't even worry
about upper case or lower case for this
about upper case or lower case for this
match exactly alright so let's go check
match exactly alright so let's go check
on Colton Ogden and all caps in the
on Colton Ogden and all caps in the
meantime Richard pointed out that we
meantime Richard pointed out that we
didn't account for Colton Ogden one word
didn't account for Colton Ogden one word
or a few other variants that's ok
or a few other variants that's ok
because I was looking for a Colton than
because I was looking for a Colton than
one or more spaces then in Ogden not the
one or more spaces then in Ogden not the
concatenation thereof a Colt and Ogden
concatenation thereof a Colt and Ogden
one word would slip under our radar yeah
one word would slip under our radar yeah
oh I'm happy to see you yet again it
oh I'm happy to see you yet again it
works nice this is a nice thing that are
works nice this is a nice thing that are
a sort of makes life easier yeah so it's
a sort of makes life easier yeah so it's
pretty intimidating honestly at first
pretty intimidating honestly at first
glance but honestly do not shy away from
glance but honestly do not shy away from
these they will tighten your code they
these they will tighten your code they
will allow you to check for things more
will allow you to check for things more
robustly we could go down even further
robustly we could go down even further
here and be more precise as to what we
here and be more precise as to what we
mean a last name is currently we're
mean a last name is currently we're
being a little lazy and we're allowing
being a little lazy and we're allowing
things like dog which is any character
things like dog which is any character
so just for kicks can you go ahead and
so just for kicks can you go ahead and
do Colton one two three Ogden yeah as a
do Colton one two three Ogden yeah as a
test case sure you know we probably
test case sure you know we probably
shouldn't tolerate this cuz at least in
shouldn't tolerate this cuz at least in
the u.s. you're not gonna have like a
the u.s. you're not gonna have like a
purely numeric middle name I think I
purely numeric middle name I think I
don't think so that probably is not you
don't think so that probably is not you
so that doesn't really meet the the test
so that doesn't really meet the the test
so dot star is a little sloppy we could
so dot star is a little sloppy we could
be more specific by specifying with
be more specific by specifying with
character classes what letters of the
character classes what letters of the
alphabet we want but we do need some
alphabet we want but we do need some
punctuation right there might be hyphens
punctuation right there might be hyphens
there might be quotes and other
there might be quotes and other
languages there might be accented
languages there might be accented
characters so we need to be a little
characters so we need to be a little
respectful of the possible variation so
respectful of the possible variation so
right for now I'm okay with dot star but
right for now I'm okay with dot star but
you know what's kind of cool too
you know what's kind of cool too
could we go ahead and could you copy
could we go ahead and could you copy
your regular expression from the carrot
your regular expression from the carrot
to the dollar sign and there's a bunch
to the dollar sign and there's a bunch
of websites that do this can you go into
of websites that do this can you go into
google now and search for like regular
google now and search for like regular
expression
expression
tester there's some really cool
tester there's some really cool
web-based applications that help you
web-based applications that help you
learn this stuff these days
learn this stuff these days
let's try a regex 101 try the first one
let's try a regex 101 try the first one
yeah this is one I've used before so
yeah this is one I've used before so
Colton just went ahead and paste it at
Colton just went ahead and paste it at
the top of the page the regular
the top of the page the regular
expression that he came up with on the
expression that he came up with on the
right hand side you'll see that there's
right hand side you'll see that there's
this explanation which is a machine
this explanation which is a machine
generated human-like summary of what it
generated human-like summary of what it
is sometimes it can get a little
is sometimes it can get a little
confusing but that might help you wrap
confusing but that might help you wrap
your mind around it but what's cool now
your mind around it but what's cool now
is go ahead and input it like a test
is go ahead and input it like a test
string give us a normal Colton Ogden
string give us a normal Colton Ogden
okay and you'll go ahead and see let's
okay and you'll go ahead and see let's
say where's my test say oh go ahead and
say where's my test say oh go ahead and
save the regular expression top left
save the regular expression top left
over there oh I think that makes it oh
over there oh I think that makes it oh
that will let us share it and we have to
that will let us share it and we have to
do the LIA this stuff that's not
do the LIA this stuff that's not
necessary because it's already there no
necessary because it's already there no
don't need that and don't need the slash
don't need that and don't need the slash
actually can you scroll down it might
actually can you scroll down it might
just be the debacle you know what we
just be the debacle you know what we
probably haven't done we probably
probably haven't done we probably
haven't done ignore case brothers
haven't done ignore case brothers
probably no no you are going right I
probably no no you are going right I
don't know oh yes we can do that click
don't know oh yes we can do that click
on the flag fires ignore you can click
on the flag fires ignore you can click
right here yeah so you can just add an
right here yeah so you can just add an
eye after that so in other languages you
eye after that so in other languages you
actually specify these lowercase symbols
actually specify these lowercase symbols
not the Python approach that makes it
not the Python approach that makes it
force it to lowercase so notice this on
force it to lowercase so notice this on
the right hand side here of Colton's
the right hand side here of Colton's
screen you'll see that it's saying match
screen you'll see that it's saying match
information and Colton Ogden is indeed a
information and Colton Ogden is indeed a
first full match David J Malan is not so
first full match David J Malan is not so
we're not seeing anything else do want
we're not seeing anything else do want
to try a few other of your cousin's try
to try a few other of your cousin's try
Colton Taylor Agha nice another full
Colton Taylor Agha nice another full
match and it actually is pieced out the
match and it actually is pieced out the
middle part here because it's in
middle part here because it's in
parentheses it's pretty cool so if you
parentheses it's pretty cool so if you
want to learn regular expressions you
want to learn regular expressions you
don't have to like struggle with your
don't have to like struggle with your
own code you can just kind of play with
own code you can just kind of play with
it a little more visually and I
it a little more visually and I
definitely use this tool in recent years
definitely use this tool in recent years
especially as my regular expressions get
especially as my regular expressions get
long and complicated because I want to
long and complicated because I want to
vet them against sample inputs outside
vet them against sample inputs outside
the context of my code okay and if we do
the context of my code okay and if we do
Colton one-two-three Ogden that's a
Colton one-two-three Ogden that's a
night doesn't happen well no if you
night doesn't happen well no if you
scroll down oh you know why because I
scroll down oh you know why because I
specified the A to Z here Oh in this
specified the A to Z here Oh in this
case you did indeed yes if I go back to
case you did indeed yes if I go back to
dot plus and get rid of character class
dot plus and get rid of character class
as
as
oh wait oh this right yep and no you
oh wait oh this right yep and no you
have the duplicate space yep guys oh but
have the duplicate space yep guys oh but
it looks like it's getting your name as
it looks like it's getting your name as
well what did I miss up there now here
well what did I miss up there now here
you have Colton spay that's weird
you have Colton spay that's weird
oh you're doing multiline get rid of the
oh you're doing multiline get rid of the
em from the flags that win global I'm
em from the flags that win global I'm
sorry not multiline global colt and no
sorry not multiline global colt and no
something's wrong can you scroll down
something's wrong can you scroll down
over here on the right
over here on the right
weird I think this is a bug it should be
weird I think this is a bug it should be
not matching it should go ahead and
not matching it should go ahead and
update the regex just for kicks even
update the regex just for kicks even
though that's under save and share just
though that's under save and share just
for kicks
for kicks
it should not be matching multiple lines
it should not be matching multiple lines
like this today yeah that's very strange
like this today yeah that's very strange
no I think that's a bug in the tool oh
no I think that's a bug in the tool oh
ok something's wrong well anyway ok on
ok something's wrong well anyway ok on
that note well let's go ahead I think we
that note well let's go ahead I think we
have a little more time to introduce one
have a little more time to introduce one
or two more features right now our
or two more features right now our
program is pretty static it just does
program is pretty static it just does
one thing and that's it if we wanted a
one thing and that's it if we wanted a
loop you know I'm kind of fond of the
loop you know I'm kind of fond of the
old games like Zelda U and I've played
old games like Zelda U and I've played
that on stream actually the original
that on stream actually the original
Zelda and it's very common to have like
Zelda and it's very common to have like
heart power HP so that you have some
heart power HP so that you have some
number of hearts representing just how
number of hearts representing just how
much health you have let's go ahead and
much health you have let's go ahead and
start from scratch in a new file called
start from scratch in a new file called
hearts a dot PI and can you just write a
hearts a dot PI and can you just write a
program that asks the user for a number
program that asks the user for a number
and then just print out that many hearts
and then just print out that many hearts
using a Unicode character sure Unicode
using a Unicode character sure Unicode
is pretty cool because you can express
is pretty cool because you can express
emojis and other things these days but
emojis and other things these days but
if you want to use ASCII based hearts
if you want to use ASCII based hearts
with like an open bracket and a 3 that's
with like an open bracket and a 3 that's
totally fine too
totally fine too
but let's just go ahead and whip this up
but let's just go ahead and whip this up
ask the user for number then print out
ask the user for number then print out
that many hearts for him or her so I'm
that many hearts for him or her so I'm
googling for heart and Unicode you know
googling for heart and Unicode you know
when you get the I want to get the
when you get the I want to get the
character and we'll use this one I think
character and we'll use this one I think
that should work let's try that
that should work let's try that
so we'll say heart char equals this
so we'll say heart char equals this
little heart character knows that
little heart character knows that
Unicode renders nicely in vs code and
Unicode renders nicely in vs code and
we'll go ahead and now here's what I
we'll go ahead and now here's what I
want to do I want to essentially take
want to do I want to essentially take
the number I'm gonna get a number as
the number I'm gonna get a number as
input and I want to
input and I want to
we multiply that number times this heart
we multiply that number times this heart
and print it out as a result hmm we're
and print it out as a result hmm we're
taking a number and actually applying it
taking a number and actually applying it
to a different string I like what you're
to a different string I like what you're
thinking but before we go this clever
thinking but before we go this clever
route could you do it a little more
route could you do it a little more
familiar relief to folks using like yeah
familiar relief to folks using like yeah
I'm kind of loop so I would say for I in
I'm kind of loop so I would say for I in
maybe the range of numb so for every eye
maybe the range of numb so for every eye
that exists in numb which is gonna be if
that exists in numb which is gonna be if
it's 5 it'll be 5 it'll happen 5 times
it's 5 it'll be 5 it'll happen 5 times
if it's tantamount to 10 times and then
if it's tantamount to 10 times and then
let's print heart charm well we'll do
let's print heart charm well we'll do
this approach for now there's a few
this approach for now there's a few
issues that we have here but we'll see
issues that we have here but we'll see
we'll see what happens when we run it so
we'll see what happens when we run it so
I'm gonna do hearts duck pie please
I'm gonna do hearts duck pie please
enter a number okay I want to see five
enter a number okay I want to see five
hearts on the screen so a stir it says
hearts on the screen so a stir it says
stir object cannot be interpreted as an
stir object cannot be interpreted as an
integer interesting and how do you know
integer interesting and how do you know
where what line is the problem so in the
where what line is the problem so in the
stack trace to the trace back it kindly
stack trace to the trace back it kindly
tells us that on line five on this for I
tells us that on line five on this for I
in range numb it's saying that the stir
in range numb it's saying that the stir
object cannot be interpreted as an
object cannot be interpreted as an
integer yeah so these are the error
integer yeah so these are the error
messages frankly early on they're gonna
messages frankly early on they're gonna
look pretty scary but if you just start
look pretty scary but if you just start
from the top especially if you get a lot
from the top especially if you get a lot
of errors start with the first one look
of errors start with the first one look
for the line number and then honestly
for the line number and then honestly
just try to wrap your mind around what
just try to wrap your mind around what
words you do understand and see if you
words you do understand and see if you
can deduce then like Colton's about to
can deduce then like Colton's about to
where the problem is exactly so I know
where the problem is exactly so I know
that numb is what I'm using here
that numb is what I'm using here
it's basically what's what I'm inputting
it's basically what's what I'm inputting
at the command line and the thing about
at the command line and the thing about
input is that it'll always return a
input is that it'll always return a
string literally what you typed in a
string literally what you typed in a
string format because they're just
string format because they're just
characters on your keyboard even though
characters on your keyboard even though
they happen to look like numbers exactly
they happen to look like numbers exactly
now the thing is I don't want I want
now the thing is I don't want I want
this to be numeric I want to be able to
this to be numeric I want to be able to
iterate over this number I want to do
iterate over this number I want to do
something x times and the way to do that
something x times and the way to do that
is we actually have to convert that
is we actually have to convert that
string into a number we have to actually
string into a number we have to actually
say in Python int of all of that stuff
say in Python int of all of that stuff
and what happens is that this input
and what happens is that this input
value I'll please enter a number the
value I'll please enter a number the
string it's actually passed to this int
string it's actually passed to this int
function which just takes in a string
function which just takes in a string
and returns you the number the numerical
and returns you the number the numerical
version of that same string yeah so
version of that same string yeah so
string 5 you get back the numbers but
string 5 you get back the numbers but
number 5 the int 5 it can read into
number 5 the int 5 it can read into
direct so let's try that so
direct so let's try that so
heart stop hi I'm gonna say number five
heart stop hi I'm gonna say number five
and okay it worries but it doesn't
and okay it worries but it doesn't
really look like heart power because
really look like heart power because
most games have it like horizontal yeah
most games have it like horizontal yeah
we fix that I think if I was a specific
we fix that I think if I was a specific
yeah so that this is a nice easy thing
yeah so that this is a nice easy thing
to do in Python so the prince is a
to do in Python so the prince is a
feature of the print statements a
feature of the print statements a
feature
feature
generally speaking or a bug-out
generally speaking or a bug-out
depending on how you look at it but it's
depending on how you look at it but it's
specifically a feature because often you
specifically a feature because often you
want to print something on the command
want to print something on the command
line but you don't want to have to
line but you don't want to have to
manually specify that I want you know
manually specify that I want you know
this input this output to go you know to
this input this output to go you know to
do a new line every time the fact it's a
do a new line every time the fact it's a
little bit tedious and the languages
little bit tedious and the languages
like C and Java you have to specifically
like C and Java you have to specifically
well not as much a Java but in C C++ you
well not as much a Java but in C C++ you
have to specify this yourself so if I
have to specify this yourself so if I
want to say just write this on the same
want to say just write this on the same
line but don't do a new line print has a
line but don't do a new line print has a
second parameter and this actually you
second parameter and this actually you
can actually see it here written out
can actually see it here written out
there's a set there's end we care about
there's a set there's end we care about
n specifically notice that it has an
n specifically notice that it has an
equal sign meaning that you can actually
equal sign meaning that you can actually
identify that argument doesn't have to
identify that argument doesn't have to
go in a specific order as long as you
go in a specific order as long as you
give it a name so if I say N equals and
give it a name so if I say N equals and
then just the empty string so nothing by
then just the empty string so nothing by
default that's a newline character by
default that's a newline character by
default into this this backslash n but I
default into this this backslash n but I
don't want to do a backslash and at the
don't want to do a backslash and at the
end of print I want to just nothing
end of print I want to just nothing
empty string and honestly this drives me
empty string and honestly this drives me
nuts about Python like it granted you
nuts about Python like it granted you
don't always want a newline character
don't always want a newline character
but this is so annoying to type a print
but this is so annoying to type a print
line yeah print versus a print line
line yeah print versus a print line
function might be might be cool yes I
function might be might be cool yes I
agree
agree
Java got this a little better yeah
Java got this a little better yeah
written in Java you have to do system
written in Java you have to do system
about out that's a bit bad but we it's
about out that's a bit bad but we it's
just ugly yeah let's go ahead and run
just ugly yeah let's go ahead and run
this now and let's say five okay so I
this now and let's say five okay so I
have my five parts but it looks like as
have my five parts but it looks like as
a byproduct of how we've coded things
a byproduct of how we've coded things
now we don't go to a new line when the
now we don't go to a new line when the
program is finished we just end right
program is finished we just end right
after the heart well that - plus all
after the heart well that - plus all
your hearts are overlapping but I think
your hearts are overlapping but I think
that's a function of your using this
that's a function of your using this
this unicode character in a mono spaced
this unicode character in a mono spaced
environment yeah yeah it's very small
environment yeah yeah it's very small
care but can we how about can we have a
care but can we how about can we have a
space after every heart
space after every heart
yeah and this up a little pensive lutely
yeah and this up a little pensive lutely
so all we need to do is say
so all we need to do is say
sepals space so separator separator and
sepals space so separator separator and
then at the very end of all of this
then at the very end of all of this
stuff at the very end I'm just gonna do
stuff at the very end I'm just gonna do
a print okay outside of the for loop
a print okay outside of the for loop
outside of the for loop because
outside of the for loop because
otherwise we'll get the same behavior
otherwise we'll get the same behavior
that we got before which was that it
that we got before which was that it
printed every it printed everything on a
printed every it printed everything on a
new line which is nice not the behavior
new line which is nice not the behavior
we were seeking jenkins from russia
we were seeking jenkins from russia
hello from cambridge this is not PyCharm
hello from cambridge this is not PyCharm
this is just the s code a free text
this is just the s code a free text
editor so if we if we enter a number
editor so if we if we enter a number
five oh and it turns out that that
five oh and it turns out that that
didn't work is maybe sep not what I'm
didn't work is maybe sep not what I'm
thinking it is no it is I think this is
thinking it is no it is I think this is
an issue of ask you know what let's go
an issue of ask you know what let's go
ahead and instead of printing out the
ahead and instead of printing out the
heart char that you have can you change
heart char that you have can you change
it to an angle bracket in a three sure
it to an angle bracket in a three sure
let's do it old-school style let's do it
let's do it old-school style let's do it
that way please enter number five still
that way please enter number five still
didn't print the space oh you know what
didn't print the space oh you know what
because you're only printing one piece
because you're only printing one piece
at a time
at a time
so you actually do here what we can
so you actually do here what we can
change in the ending to be a space will
change in the ending to be a space will
do this and then we'll go and then we'll
do this and then we'll go and then we'll
bring back our our heart character I'll
bring back our our heart character I'll
see if that actually fixes it so we'll
see if that actually fixes it so we'll
copy that separator would work if you
copy that separator would work if you
were passing in multiple inputs like a
were passing in multiple inputs like a
list that needs to be printed on oh I
list that needs to be printed on oh I
say okay well then we can there is a way
say okay well then we can there is a way
we could do that now let's go ahead and
we could do that now let's go ahead and
we'll type we'll do this again enter
we'll type we'll do this again enter
five and then we have nice long I should
five and then we have nice long I should
answer okay the five hearts okay very
answer okay the five hearts okay very
nice now you started I think to go down
nice now you started I think to go down
a pretty sophisticated road that might
a pretty sophisticated road that might
be unfamiliar to a lot of folks do you
be unfamiliar to a lot of folks do you
absolutely need to the for loop like
absolutely need to the for loop like
this or is there a more pythonic way to
this or is there a more pythonic way to
do there is a more pythonic way and this
do there is a more pythonic way and this
is something that's more specific to the
is something that's more specific to the
way python handles strings python is
way python handles strings python is
actually overloaded the multiplication
actually overloaded the multiplication
operator so in the same way that it's
operator so in the same way that it's
overloaded the plus sign to allow you to
overloaded the plus sign to allow you to
add two strings together end to end it's
add two strings together end to end it's
actually giving you the ability to use
actually giving you the ability to use
the multiplication sign the asterisk
the multiplication sign the asterisk
which we haven't actually looked at yet
which we haven't actually looked at yet
to allow string multiplication now
to allow string multiplication now
normally it's not a thing in the real
normally it's not a thing in the real
world but in Python but that essentially
world but in Python but that essentially
does is it just outputs that string x
does is it just outputs that string x
times depending on what the multiplier
times depending on what the multiplier
is correct so if we say let's say
is correct so if we say let's say
instead of what we did before let's
instead of what we did before let's
actually print heart char x now
actually print heart char x now
so we're actually multiplying this heart
so we're actually multiplying this heart
string by the gnome that we've converted
string by the gnome that we've converted
into an integer up top nice we run this
into an integer up top nice we run this
and enter 5 and we get the same behavior
and enter 5 and we get the same behavior
unfortunately that we had before
unfortunately that we had before
now there is another way we can do this
now there is another way we can do this
if we wanted to use what's called a list
if we wanted to use what's called a list
comprehension if you wanted to talk
comprehension if you wanted to talk
about if we want to bring that up what's
about if we want to bring that up what's
up what are we gonna use it for and we
up what are we gonna use it for and we
would actually turn this into a list of
would actually turn this into a list of
five of these then we can use set with
five of these then we can use set with
space yeah you know you're not wrong
space yeah you know you're not wrong
that that would actually help here so
that that would actually help here so
yeah let's go for it let's all write a
yeah let's go for it let's all write a
little teaser for what more you can do
little teaser for what more you can do
with Python
with Python
so we'll say we'll do this thing we'll
so we'll say we'll do this thing we'll
say heart first of all I'm not going to
say heart first of all I'm not going to
call it heart char anymore because
call it heart char anymore because
that's not accurate we're gonna say
that's not accurate we're gonna say
hearts equals and then this is gonna be
hearts equals and then this is gonna be
a little bit of odd syntax so it's gonna
a little bit of odd syntax so it's gonna
look similar to lists that we've looked
look similar to lists that we've looked
at before but I'm gonna say for I in
at before but I'm gonna say for I in
numb like Vince so hearts equals the
numb like Vince so hearts equals the
unicode heart for every eye in numb so
unicode heart for every eye in numb so
these brackets here they're creating a
these brackets here they're creating a
list just like we did before but we're
list just like we did before but we're
using an expression to actually create a
using an expression to actually create a
list programmatically we're saying for
list programmatically we're saying for
every eye and numb so from 0 it's 2 of 4
every eye and numb so from 0 it's 2 of 4
in this case 0 to 5 we're going to add
in this case 0 to 5 we're going to add
this the heart character okay so at the
this the heart character okay so at the
end of all and at the end of this line
end of all and at the end of this line
here essentially gonna have this we're
here essentially gonna have this we're
gonna have this in a list it's
gonna have this in a list it's
essentially the same a same exact thing
essentially the same a same exact thing
very nice and so now what we can do is
very nice and so now what we can do is
we can say print hearts set equals the
we can say print hearts set equals the
space character because we're printing a
space character because we're printing a
list of things and actually I'm I think
list of things and actually I'm I think
you're gonna print the list but let's go
you're gonna print the list but let's go
ahead and see what you've done I think
ahead and see what you've done I think
we're gonna print the list actually so I
we're gonna print the list actually so I
need to I need to refresh my mind on how
need to I need to refresh my mind on how
set actually works but I'll do 5 and
set actually works but I'll do 5 and
then a int object is not iterable oh I
then a int object is not iterable oh I
messed that up so you can't actually
messed that up so you can't actually
iterate on the number itself you
iterate on the number itself you
actually have to call range of them so
actually have to call range of them so
range gives you back the number 0 up to
range gives you back the number 0 up to
5 or s case if you type in yeah
5 or s case if you type in yeah
it's a it's what's called a generator in
it's a it's what's called a generator in
that it gives you values every time you
that it gives you values every time you
call it over and over again but that's
call it over and over again but that's
beyond the scope I think
beyond the scope I think
of this tutorial nice so now you have a
of this tutorial nice so now you have a
list a data type containing five hearts
list a data type containing five hearts
we did so what can we do with this now
we did so what can we do with this now
because you're printing it out but we
because you're printing it out but we
don't want the square brackets or the
don't want the square brackets or the
quotes or anything like that so I need
quotes or anything like that so I need
to look and see how step actually works
to look and see how step actually works
so Python print set I don't use it too
so Python print set I don't use it too
often set parameter in print
often set parameter in print
oh I see so if you're actually if you
oh I see so if you're actually if you
actually pass it multiple things in the
actually pass it multiple things in the
in the parentheses now is there a way to
in the parentheses now is there a way to
unpack I think there is and actually
unpack I think there is and actually
think I might know it offhand if we were
think I might know it offhand if we were
to say print hearts star except those
to say print hearts star except those
that not right or is it star hearts
that not right or is it star hearts
we're not allowed to do that I think it
we're not allowed to do that I think it
starts so first of all let's test to
starts so first of all let's test to
make sure that works before I before I
make sure that works before I before I
okay it does work and then we'll explain
okay it does work and then we'll explain
why it works so this star operator is
why it works so this star operator is
not multiplication in this case this is
not multiplication in this case this is
actually an unpacking operator so if you
actually an unpacking operator so if you
have a data structure in this case the
have a data structure in this case the
list but you want to pass every element
list but you want to pass every element
of that data structure into a function
of that data structure into a function
like you were literally calling print of
like you were literally calling print of
this five times like this whoops I
this five times like this whoops I
messed that up a little bit but if we
messed that up a little bit but if we
were doing essentially that without the
were doing essentially that without the
syntax error we we can't do that by
syntax error we we can't do that by
passing in just the list object because
passing in just the list object because
that's just one argument but if you want
that's just one argument but if you want
to unpack all of the data within the
to unpack all of the data within the
list you can explode it in a comma
list you can explode it in a comma
separated list about it I think that's
separated list about it I think that's
actually the term I think it's called
actually the term I think it's called
the explode operator or something
the explode operator or something
something like that and you can also or
something like that and you can also or
splaying in JavaScript these days so if
splaying in JavaScript these days so if
you go to hearts - can I propose one
you go to hearts - can I propose one
other approach yeah
other approach yeah
if hearts on line five is a list you can
if hearts on line five is a list you can
also do this if you know in advance how
also do this if you know in advance how
you want to separate the elements of any
you want to separate the elements of any
list there you go you can go ahead and
list there you go you can go ahead and
do quote space unquote right dot join
do quote space unquote right dot join
but give me a space between the quotes
but give me a space between the quotes
alright because we're doing it on space
alright because we're doing it on space
as one of that space separate join the
as one of that space separate join the
hearts and get rid of the separator
hearts and get rid of the separator
altogether so now we're not asking for
altogether so now we're not asking for
prints help instead we're gonna pass to
prints help instead we're gonna pass to
print the result of joining of that list
print the result of joining of that list
of heart with one space in between and
of heart with one space in between and
this way - nicely enough you don't end
this way - nicely enough you don't end
up for instance with an accidental space
up for instance with an accidental space
at the very end that's there even if you
at the very end that's there even if you
can't see it right and this
can't see it right and this
this approach is cleaner I think more of
this approach is cleaner I think more of
a pythonic way to do it so we'll do five
a pythonic way to do it so we'll do five
and then we can lie exact same behavior
and then we can lie exact same behavior
but we've we've actually made it a
but we've we've actually made it a
little bit I think clearer we save some
little bit I think clearer we save some
space in our code yeah absolutely it's a
space in our code yeah absolutely it's a
pretty cool so I think we're we're just
pretty cool so I think we're we're just
about at the end of the hour here and so
about at the end of the hour here and so
what were some of the takeaways we hope
what were some of the takeaways we hope
so one all you need for python is a text
so one all you need for python is a text
edit or whether it's the one Colton is
edit or whether it's the one Colton is
using here or really any other and you
using here or really any other and you
need Python itself preferably version
need Python itself preferably version
three which you can download for free
three which you can download for free
the Python org and then after that
the Python org and then after that
notice that if you've programmed before
notice that if you've programmed before
there's a lot of familiar constructs
there's a lot of familiar constructs
you've got functions and you've got
you've got functions and you've got
variables and assignment and conditions
variables and assignment and conditions
and loops but then you have these
and loops but then you have these
fancier features like regular
fancier features like regular
expressions so powerful not only in
expressions so powerful not only in
Python but other languages but also some
Python but other languages but also some
of these syntactic tricks like list
of these syntactic tricks like list
comprehensions as colton notes and a lot
comprehensions as colton notes and a lot
of the object-oriented features that
of the object-oriented features that
we've also touched upon over time so
we've also touched upon over time so
honestly I think personally I would say
honestly I think personally I would say
the biggest takeaway for today should be
the biggest takeaway for today should be
please do not be afraid of regular
please do not be afraid of regular
expressions they can absolutely get
expressions they can absolutely get
scary but they don't have to start that
scary but they don't have to start that
way and so if you really do take baby
way and so if you really do take baby
steps and just solve part of your Colton
steps and just solve part of your Colton
problem then more of your ogden problem
problem then more of your ogden problem
and then take care of everything in
and then take care of everything in
between you really can bootstrap
between you really can bootstrap
yourself so to speak to a really
yourself so to speak to a really
impressive solution that you're proud of
impressive solution that you're proud of
without having to know what their answer
without having to know what their answer
is right off the top of your head we
is right off the top of your head we
have a lot of Colton Ogden problems we
have a lot of Colton Ogden problems we
do we are so unhappy to see so many
do we are so unhappy to see so many
Colton Ogden's today as well as in the
Colton Ogden's today as well as in the
chat I saw Colton's hair yeah one day
chat I saw Colton's hair yeah one day
the pointers too many thanks everybody
the pointers too many thanks everybody
for tuning in we this is this is pretty
for tuning in we this is this is pretty
fun maybe in the future if we can find
fun maybe in the future if we can find
the time we'll do a part two because
the time we'll do a part two because
there's a million different things we
there's a million different things we
could talk about but hopefully this at
could talk about but hopefully this at
least wet your appetite for what Python
least wet your appetite for what Python
is capable of doing very easily very
is capable of doing very easily very
cleanly especially if you come from a
cleanly especially if you come from a
background programming and something
background programming and something
like C or Java where things are a little
like C or Java where things are a little
bit more less managed for you absolutely
bit more less managed for you absolutely
so feel free to tinker and let us know
so feel free to tinker and let us know
via various cs50 various channels if you
via various cs50 various channels if you
have any questions but looking forward
have any questions but looking forward
to seeing everyone again and have a
to seeing everyone again and have a
great weekend youtube.com slash cs50
great weekend youtube.com slash cs50
facebook.com slash news 50 check out our
facebook.com slash news 50 check out our
content cool am on the note have a great
content cool am on the note have a great
weekend we will see you actually I won't
weekend we will see you actually I won't
be here next week I'm going to Japan but
be here next week I'm going to Japan but
the week after that I will see all of
the week after that I will see all of
you so in the meantime you know enjoy
you so in the meantime you know enjoy
enjoy your weekend dude time
enjoy your weekend dude time
break from Colton Ogden because you know
break from Colton Ogden because you know
way we that unhappy face every bit a
way we that unhappy face every bit a
little bit of that is too much but in
little bit of that is too much but in
the meantime I'll miss all of you and
the meantime I'll miss all of you and
we'll see you in just a couple of weeks
we'll see you in just a couple of weeks
so until then take care
so until then take care
all right hello world this is cs50 live. my name is Colton Ogden today we're. joined by the man himself. David Malin hello everyone good to see. everyone on stream and not just in the. chat today we are doing something pretty. cool today pretty fun we're doing a from. scratch of Python tutorial and my. understanding is that you've actually. brought some questions and topics. problem challenges that I haven't seen. that we're gonna implement and I'm gonna. sort of be a proxy to somebody who maybe. is learning for the first time indeed so. I'm gonna pretty much assume that Colton. may or may not actually know Python and. so along the way we'll try to solve some. problems actively by a coding we'll pull. things up by Google or Stack Overflow as. we go and frankly try to approximate the.
tool, utensil, or other piece of equipment. To start to do something you plan to do.
/ˈCHalənj/
invitation to compete/fight. Questions to determine correctness of some things. To formally invite someone to compete at something.
/ˈkwesCH(ə)n/
sentence worded or expressed so as to elicit information. Issues or problems you are dealing with. ask someone questions.
/ˈrīdiNG/
activity or skill of writing. To invent or create a computer program. To compose letters and words on paper or a screen.
/skraCH/
assembled or made from whatever is available, and so unlikely to be of highest quality. Action of rubbing your skin when itchy. To make a small cut or mark on a surface.
/ˌəndərˈstandiNG/
sympathetically aware of other people's feelings. ability to understand something. To know the meaning of language, what someone says.
/ˈpräbləm/
Causing trouble. Question to show understanding of a math concept.
/t(y)o͞oˈtôrēəl/
relating to tutor or tutor's tuition. A lesson given to a small group.
/ˈlərniNG/
acquisition of knowledge or skills through study. To get knowledge or skills by study or experience.
/ˌikˈspirēəns/
An event at which you learned something. To gain knowledge by doing things.
close to actual, but not completely accurate or exact. To be similar to, but not exactly the same.
Metric | Count | EXP & Bonus |
---|---|---|
PERFECT HITS | 20 | 300 |
HITS | 20 | 300 |
STREAK | 20 | 300 |
TOTAL | 800 |
Sign in to unlock these awesome features: