[closed] HW- 5.4 Please Clear .

Hello,

Can anybody tell me how can we get the value of a <"keyword"> when we have its <"value"> ?

Till now , we been doing its reverse. So this thing is kinda new to me.

asked 24 Mar '12, 14:43

Estilo's gravatar image

Estilo
15151026
accept rate: 0%

closed 24 Mar '12, 16:07

The question has been closed for the following reason "The question is answered, right answer was accepted" by Estilo 24 Mar '12, 16:07


3 Answers:

Don't forget all the list handling we've been doing for a while.
Not because we now know dictionaries that everything else is not good anymore...

With a dictionary we can get the content by giving the keywork directly (dict[keyword]), which is cool, but we can still enumerate the keys as keywords in lists.

link

answered 24 Mar '12, 14:47

Angel's gravatar image

Angel
7.0k632112

edited 24 Mar '12, 15:30

But list operations are fail on dictionary.

(24 Mar '12, 14:50) Estilo Estilo's gravatar image

Hmm now that I look at it again, I must admin I used a method on the dictionary that has net been covered yet...
Which I changed after @yoshi's comment. There are similarities between lists and dictionaries.

(24 Mar '12, 14:58) Angel Angel's gravatar image

Try using a for loop to go through all the keywords. For some inspiration, take a look at the example given in the homework.

def courses_offered(courses, hexamester):
    res = []
    for c in courses[hexamester]:
        res.append(c)
    return res
link

answered 24 Mar '12, 15:07

yoshi's gravatar image

yoshi
4.0k82659

But this implies we have the hexamester, which we don't...

(24 Mar '12, 15:14) Angel Angel's gravatar image
1

True, but this is one level into the dictionary. You can always just do

for hexamester in courses:

and traverse the hexamesters through that, just like you would for a list.

(24 Mar '12, 15:16) yoshi yoshi's gravatar image

Yeah! I am still not getting the idea of knowing 'keyword' when I have its 'value'. :/

(24 Mar '12, 15:17) Estilo Estilo's gravatar image

Think about it from the list point of view, how would you get all the keywords if you knew the url?

(24 Mar '12, 15:21) yoshi yoshi's gravatar image

@yoshi Doh! /facepalm
@Estilo go from what yoshi wrote (comment). Test key's value against your value....

(24 Mar '12, 15:24) Angel Angel's gravatar image
-1

OMG! Finally I got it.

:/ It took me 1 hour. One things is for sure. Dictionary is really new to me.

Thanks a lot @yoshi and @angel

link

answered 24 Mar '12, 15:32

Estilo's gravatar image

Estilo
15151026

Glad answers were helpful!

(24 Mar '12, 15:33) Angel Angel's gravatar image

I would have got it in few mins but I just ignored the main key that I was sure of . LOL

(24 Mar '12, 15:34) Estilo Estilo's gravatar image

You're welcome :)

(24 Mar '12, 15:40) yoshi yoshi's gravatar image

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,307
×1,718
×57
×18
×5

Asked: 24 Mar '12, 14:43

Seen: 319 times

Last updated: 24 Mar '12, 16:07