《计算机科学导论》学习笔记(15) - 课程 15 响应查询

课程 15:响应查询

1. 简介

2. 练习:数据结构

3. 练习:添加索引

题目:

# Define a procedure, add_to_index,
# that takes 3 inputs:

# - an index: [[<keyword>,[<url>,...]],...]
# - a keyword: String
# - a url: String

# If the keyword is already
# in the index, add the url
# to the list of urls associated
# with that keyword.

# If the keyword is not in the index,
# add an entry to the index: [keyword,[url]]

index = []

def add_to_index(index,keyword,url):








#add_to_index(index,'udacity','http://udacity.com')
#add_to_index(index,'computing','http://acm.org')
#add_to_index(index,'udacity','http://npr.org')
#print index
#>>> [['udacity', ['http://udacity.com', 'http://npr.org']], 
#>>> ['computing', ['http://acm.org']]]

我的答案(我搞不出来…):

def add_to_index(index,keyword,url):

    if index.



    index.append([keyword, [url]])
    """

    for i in range(len(index)):
        if keyword not in index[i]:
            index.append([keyword])

    for i in range(len(index)):
        if len(index[i]) == 1:
            index[i].append([])
        if index[i][0] == keyword:
            index[i][1].append(url)
    """

    """
    for i in range(len(index)):
        if index[i][0] == keyword:
            index[i][1].append(url)
    return index
    """

视频的答案(我看的不是很懂):

index = []

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





add_to_index(index,'udacity','http://udacity.com')

add_to_index(index,'computing','http://acm.org')
add_to_index(index,'udacity','http://npr.org')

print index
#>>> [['udacity', ['http://udacity.com', 'http://npr.org']], 
#>>> ['computing', ['http://acm.org']]]

4. 练习:查询

5. 构建网络索引

6. 练习:添加页面至索引

7. 练习:完成网络爬虫

8. 启动

9. 因特网

10. 练习:网络

11. 烟幕信号

12. 练习:延迟

13. 带宽

14. 练习:比特

15. 比特桶

16. 练习:你的带宽是多少?

17. 跟踪路由

( Linux 下的跟踪方式:
1 . 安装 traceroute :

$ sudo apt-get install traceroute
  1. 跟踪访问某个网站的路由:
$ traceroute www.udacity.com

)

18. 练习:传输数据

19. 制造网络

20. 协议

21. 结论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值