Press "Enter" to skip to content

Hands-On Golang Exercise – Map Key Index


this hands-on exercise I want you to

this hands-on exercise I want you to create a map with a key of type string

create a map with a key of type string

create a map with a key of type string which is a person’s last underscore

which is a person’s last underscore

which is a person’s last underscore first name and a value of type slice of

first name and a value of type slice of

first name and a value of type slice of string make that big two which stores

string make that big two which stores

string make that big two which stores their favorite things store three

their favorite things store three

their favorite things store three records in your map and I have a

records in your map and I have a

records in your map and I have a possible data set right here which I’m

possible data set right here which I’m

possible data set right here which I’m gonna copy for you print out all of the

gonna copy for you print out all of the

gonna copy for you print out all of the values along with their index position

values along with their index position

values along with their index position in the slice so pause the video right

in the slice so pause the video right

in the slice so pause the video right now go do that a hands-on exercise in

now go do that a hands-on exercise in

now go do that a hands-on exercise in the goin playground when you’ve finished

the goin playground when you’ve finished

the goin playground when you’ve finished come back and restart this video or

come back and restart this video or

come back and restart this video or unpause this video so continues playing

unpause this video so continues playing

unpause this video so continues playing because now right now I’m gonna show you

because now right now I’m gonna show you

because now right now I’m gonna show you the solution so let’s go to the golang

the solution so let’s go to the golang

the solution so let’s go to the golang playground and first thing i’m going to

playground and first thing i’m going to

playground and first thing i’m going to do is create a math using a composite

do is create a math using a composite

do is create a math using a composite literal so short declaration operator

literal so short declaration operator

literal so short declaration operator map it’s gonna have a key of string and

map it’s gonna have a key of string and

map it’s gonna have a key of string and then a slice of string as the value and

then a slice of string as the value and

then a slice of string as the value and then composite literal so there is the

then composite literal so there is the

then composite literal so there is the type we have the type this is the type

type we have the type this is the type

type we have the type this is the type and then we have the curly braces and we

and then we have the curly braces and we

and then we have the curly braces and we put the values there so that’s a

put the values there so that’s a

put the values there so that’s a composite literal the type curly braces

composite literal the type curly braces

composite literal the type curly braces put the value right there so now I’m

put the value right there so now I’m

put the value right there so now I’m going to come down here and put in the

going to come down here and put in the

going to come down here and put in the values and those values are gonna be

values and those values are gonna be

values and those values are gonna be like this

like this

like this but I’ll do it like yeah that’s fine

but I’ll do it like yeah that’s fine

but I’ll do it like yeah that’s fine I’ll do it like that command V and then

I’ll do it like that command V and then

I’ll do it like that command V and then this will be a colon and then we need a

this will be a colon and then we need a

this will be a colon and then we need a slice of string and that to make a new

slice of string and that to make a new

slice of string and that to make a new composite literal and then it ends right

composite literal and then it ends right

composite literal and then it ends right here and a comma and now we do the next

here and a comma and now we do the next

here and a comma and now we do the next one and we have the key colon and then

one and we have the key colon and then

one and we have the key colon and then the value and it’s gonna be a slice of

the value and it’s gonna be a slice of

the value and it’s gonna be a slice of string and Miss Moneypenny likes James

string and Miss Moneypenny likes James

string and Miss Moneypenny likes James Bond literature computer science because

Bond literature computer science because

Bond literature computer science because she is awesome and then we’re gonna come

she is awesome and then we’re gonna come

she is awesome and then we’re gonna come here and we’re gonna do doctor no and

here and we’re gonna do doctor no and

here and we’re gonna do doctor no and dr. noha likes being evil ice cream and

dr. noha likes being evil ice cream and

dr. noha likes being evil ice cream and sunsets it’s actually a fascinating guy

sunsets it’s actually a fascinating guy

sunsets it’s actually a fascinating guy aside from that being evil part it’s got

aside from that being evil part it’s got

aside from that being evil part it’s got some eclectic interests alright so there

some eclectic interests alright so there

some eclectic interests alright so there we go there’s our map and let’s print it

we go there’s our map and let’s print it

we go there’s our map and let’s print it out just make sure it all works sweet

out just make sure it all works sweet

out just make sure it all works sweet there’s our map so now the next thing we

there’s our map so now the next thing we

there’s our map so now the next thing we want to do is we want to capture our

want to do is we want to capture our

want to do is we want to capture our print

print

print all the values so I’m just gonna comment

all the values so I’m just gonna comment

all the values so I’m just gonna comment that out so we keep our output a little

that out so we keep our output a little

that out so we keep our output a little bit clean and we’re gonna do a four key

bit clean and we’re gonna do a four key

bit clean and we’re gonna do a four key value : equals range over our mount and

value : equals range over our mount and

value : equals range over our mount and we’re gonna get that all that stuff out

we’re gonna get that all that stuff out

we’re gonna get that all that stuff out so here we could format print line and

so here we could format print line and

so here we could format print line and we could say you know this is and the

we could say you know this is and the

we could say you know this is and the key is going to be their name this is

key is going to be their name this is

key is going to be their name this is the record for and then we’ll do key

the record for and then we’ll do key

the record for and then we’ll do key right and then what we’ll do is four

right and then what we’ll do is four

right and then what we’ll do is four will do another four range so for index

will do another four range so for index

will do another four range so for index value to call on equals range and we’re

value to call on equals range and we’re

value to call on equals range and we’re gonna range over this value which is

gonna range over this value which is

gonna range over this value which is gonna be that slice of string right

gonna be that slice of string right

gonna be that slice of string right because the key the key is associated

because the key the key is associated

because the key the key is associated with a slice of string cool you know put

with a slice of string cool you know put

with a slice of string cool you know put our curly braces in and they will bumped

our curly braces in and they will bumped

our curly braces in and they will bumped print line and we’ll do a tab and then

print line and we’ll do a tab and then

print line and we’ll do a tab and then index and value format at all and run it

index and value format at all and run it

index and value format at all and run it be to declare do not use there we go

be to declare do not use there we go

be to declare do not use there we go this is the record for doctor no being

this is the record for doctor no being

this is the record for doctor no being evil ice cream sunsets this is the

evil ice cream sunsets this is the

evil ice cream sunsets this is the record for bond James shaken not stirred

record for bond James shaken not stirred

record for bond James shaken not stirred martinis in women yeah he is a

martinis in women yeah he is a

martinis in women yeah he is a misogynist I agree this is the right and

misogynist I agree this is the right and

misogynist I agree this is the right and that’s not a good thing we are all equal

that’s not a good thing we are all equal

that’s not a good thing we are all equal this is a record for Moneypenny mess but

this is a record for Moneypenny mess but

this is a record for Moneypenny mess but I grew up reading Ian Fleming novels

I grew up reading Ian Fleming novels

I grew up reading Ian Fleming novels still fan of the movies this is a record

still fan of the movies this is a record

still fan of the movies this is a record for Miss Moneypenny James Bond

for Miss Moneypenny James Bond

for Miss Moneypenny James Bond literature in computer science

literature in computer science

literature in computer science alright sweet so that’s an example for

alright sweet so that’s an example for

alright sweet so that’s an example for hands-on exercise number seven number

hands-on exercise number seven number

hands-on exercise number seven number eight hands-on exercise number eight

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *