Structs and Maps

Take a look at this little program, because that is what it is, isn’t it a program?


Would it be possible to make a map showing the name of the subject, the name of the teacher, and the time of the class? I don’t know what type of type shows a time.

Here is an attempt at the map, not including the time

If you are fine storing the time of the class as a string, you can, if you want to have it as another type, you can’t.

It feels as if you want a struct there.

Interesting. I’ll make an attempt.

So would I use map[string]string string?

There is no map[string]string string (if I read you right).

If you want to throw some string representation into a map[string]string, its like this:

m := make(map[string]string)
m["date"] = "2018-01-01"

But you really rarely want that.

Also that wouldn’t suit your data, which seemed to map a courses name to its teacher in the map. If you put the date in there, it would look like a “course” named date, taught by “2018-01-01”.

As I said, you probably want to rething your datastructure.

I’m going to study this.

Here’s my attempt.

I got: unexpected newline, expecting comma or }

Yet I did put “}” there.

I’ve put , at the end of the lines that go complained about missing them and it seems to work then:


{History Mr. Towers 4 [8:00]}
{Latin Mrs. Martin 2 [9:30]}
History Mr. Towers 4
Latin Mrs. Martin 2

map[History:Mr. Towers Latin:Mrs. Martin]

So, what I was missing was a couple commas. Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.