HW 4.5 and 4.6 Incorrecct?

I don't understand why these are incorrect. Could someone please point out my errors?

@PeterUdacity In case my answers turn out to be correct, and since I've seen you ask others the same question: I did not use an external editor.

4.5 Better Splitting:

def split_string(source,splitlist):
    list = []
    start = 0
    for i in range(len(source)):
        if source[i] in splitlist:
            if start < i:
                list.append(source[start:i])
            start = i + 1
        else:
            if i == len(source) - 1:
                list.append(source[start:])
    return list

4.6 Improving the Index

def add_to_index(index, keyword, url):
    for entry in index:
        if entry[0] == keyword:
            if url in entry[1]:
                return
            entry[1].append(url)
            return
    index.append([keyword, [url]])

asked 21 Mar '12, 21:35

pseudonoob's gravatar image

pseudonoob
200312
accept rate: 40%

edited 21 Mar '12, 21:53


One Answer:

Have you tried to resubmit your code? There is sometimes an error message telling you what was wrong.

Your split string code doesn't return anything.

link

answered 21 Mar '12, 21:41

fnenu-1's gravatar image

fnenu-1 ♦♦
18.5k1981231

edited 21 Mar '12, 21:43

I missed the return statement in the copy-paste to the forums. I've fixed it. How do I resubmit my code? I thought the grading was only done once.

(21 Mar '12, 21:55) pseudonoob pseudonoob's gravatar image

The grading is only done once, but after the deadline it's just like a quiz so you can submit it again and get some sort of message about why it was marked wrong. It won't change the homework grade though.

(22 Mar '12, 23:01) fnenu-1 ♦♦ fnenu-1's gravatar image
Your answer
Question text:

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,880
×1,718
×87
×41
×15
×12

Asked: 21 Mar '12, 21:35

Seen: 178 times

Last updated: 22 Mar '12, 23:01