Python 有人能举例说明这个函数应该做什么吗?

Python 有人能举例说明这个函数应该做什么吗?,python,dictionary,graph,Python,Dictionary,Graph,基本上,我理解代码应该做什么,但不确定将URL映射到目标URL列表的字典意味着什么。有人能举个例子吗 WEB_DATA = os.path.join(os.path.dirname(__file__), 'school_web.txt') def load_graph(fd): """Load graph from text file Parameters: fd -- a file like object that contains lines of URL pai

基本上,我理解代码应该做什么,但不确定将URL映射到目标URL列表的字典意味着什么。有人能举个例子吗

WEB_DATA = os.path.join(os.path.dirname(__file__), 'school_web.txt')

def load_graph(fd):
    """Load graph from text file

    Parameters:
    fd -- a file like object that contains lines of URL pairs

    Returns:
    A dict mapping a URL (str) to a list of target URLs (str).
    """

    # Iterate through the file line by line
    for line in fd:
        # And split each line into two URLs
        node, target = line.split()
        raise RuntimeError("This function is not implemented yet.")

我可以想象一个字典将一个url映射到一个url列表

{ 'https://google.com': ['https://example.com', 'https://stackoverflow.com'],
  'https://duckduckgo.com': ['https://twitter.com'] }
这有意义吗



您是否意识到,该函数总是返回一个
运行时错误
来抱怨一些本应
未实现的错误

输入参数是一个文件描述符,它是为包含由一些空格分隔的URL行的文件打开的

url1 url2 
url1 url3
url2 url3
假设,您将第一列中的每个url组合在一起,并构建传出目标的列表