Slice在udacity的python解释器中不工作

Slice在udacity的python解释器中不工作,python,Python,我使用python for udacity在Challage中编写了此函数: example_input="John is connected to Bryant, Debra, Walter.\ John likes to play The Movie: The Game, The Legend of Corgi, Dinosaur Diner.\ Bryant is connected to Olive, Ollie, Freda, Mercedes.\ Bryant likes to pl

我使用python for udacity在Challage中编写了此函数:

example_input="John is connected to Bryant, Debra, Walter.\
John likes to play The Movie: The Game, The Legend of Corgi, Dinosaur Diner.\
Bryant is connected to Olive, Ollie, Freda, Mercedes.\
Bryant likes to play City Comptroller: The Fiscal Dilemma, Super Mushroom Man.\
Mercedes is connected to Walter, Robin, Bryant.\
Mercedes likes to play The Legend of Corgi, Pirates in Java Island, Seahorse Adventures.\
Olive is connected to John, Ollie.\
Olive likes to play The Legend of Corgi, Starfleet Commander.\
Debra is connected to Walter, Levi, Jennie, Robin.\
Debra likes to play Seven Schemers, Pirates in Java Island, Dwarves and Swords.\
Walter is connected to John, Levi, Bryant.\
Walter likes to play Seahorse Adventures, Ninja Hamsters, Super Mushroom Man.\
Levi is connected to Ollie, John, Walter.\
Levi likes to play The Legend of Corgi, Seven Schemers, City Comptroller: The Fiscal Dilemma.\
Ollie is connected to Mercedes, Freda, Bryant.\
Ollie likes to play Call of Arms, Dwarves and Swords, The Movie: The Game.\
Jennie is connected to Levi, John, Freda, Robin.\
Jennie likes to play Super Mushroom Man, Dinosaur Diner, Call of Arms.\
Robin is connected to Ollie.\
Robin likes to play Call of Arms, Dwarves and Swords.\
Freda is connected to Olive, John, Debra.\
Freda likes to play Starfleet Commander, Ninja Hamsters, Seahorse Adventures."def create_data_structure(string_input):
for x in string_input:
    if not ((ord(x)>60 and ord(x)<90) or x=="." or (ord(x)>97 and ord(x)<122)):
    string_input=string_input[:string_input.index(x)]+string_input[string_input.index(x):]
    network={}
    before=0
    string_input2=string_input
    while y < string_input.count('.')+1:
        network[y]=string_input2(0:before)
        string_input2=string_input2(:before-1)
        before=string_input2.find('.')
    return network,len(string_input),string_input
example\u input=“约翰与布莱恩特、黛布拉、沃尔特有联系\
约翰喜欢玩电影:《游戏》、《科基传奇》、《恐龙食客》\
布莱恩特和奥利夫、奥利、弗雷达、梅赛德斯都有联系\
布莱恩特喜欢扮演城市审计官:财政困境,超级蘑菇人\
梅赛德斯和沃尔特、罗宾、布莱恩特有联系\
梅赛德斯喜欢扮演科基传奇、爪哇岛海盗、海马冒险\
奥利弗和约翰、奥利有联系\
奥利弗喜欢扮演星际舰队指挥官科基的传奇人物\
黛布拉与沃尔特、利维、珍妮和罗宾有联系\
黛布拉喜欢扮演七个阴谋家、爪哇岛海盗、矮人和剑\
沃尔特与约翰、利维、布莱恩特有联系\
沃尔特喜欢玩海马冒险,忍者仓鼠,超级蘑菇人\
李维与奥利、约翰、沃尔特有联系\
李维喜欢扮演科基传奇,七个阴谋家,城市审计官:财政困境\
奥利和梅赛德斯、弗雷达、布莱恩特有联系\
奥利喜欢玩《武器召唤》、《矮人与剑》,电影:游戏\
珍妮与李维、约翰、弗雷达、罗宾有联系\
珍妮喜欢扮演超级蘑菇人、恐龙食客、武器召唤\
罗宾和奥利有联系\
罗宾喜欢玩武器召唤、矮人和剑\
弗雷达和奥利夫、约翰、黛布拉有联系\
弗雷达喜欢扮演星际舰队指挥官、忍者仓鼠、海马探险。“def创建数据结构(字符串输入):
对于字符串_输入中的x:

如果不是((ord(x)>60和ord(x)97以及ord(x)语法,则在Python中分割字符串/列表/元组是
[:]
而不是
(:)
,即使用括号而不是括号。尝试:

例如:

>>> my_string = 'StackOverflow'
>>> my_string[5:9]
'Over'

切片表示法使用方括号…我的朋友,您需要看看python语法。
string_input2[0:11]
>>> my_string = 'StackOverflow'
>>> my_string[5:9]
'Over'