题解 | #牛牛的朋友#
牛牛的朋友
http://www.nowcoder.com/practice/11bcc9a775b14d9f9b855634b9434b70
NP33 牛牛的朋友
思路:
step1:首先创建并打印原列表;
step2:定义replace函数,将friends[index] = index;
step3:遍历列表,每次遍历,均调用一下replace函数;
step4:打印更新后的列表;
代码如下:
friends_list = ['Niu Ke Le', 'Niumei', 'Niuneng', 'GOLO']
print(friends_list)
def replace(friends_list,index):
friends_list[index] = index
for i in range(len(friends_list)):
replace(friends_list,i)
print(friends_list)