附加两次列表

时间:2017-03-19 17:37:19

标签: python

我正在试图弄清楚如何创建一个程序,可以根据他们共同的朋友推荐用户朋友。特别是如果两个人是共同的朋友,我想将他们的用户ID放入列表中。例如,如果用户A是B和C的共同朋友,我希望A的列表看起来像:

A: [B, C]

如果B只是A的朋友,我希望B的列表看起来像:

B: [A]

如何附加列表以便将特定用户的好友ID放入用户列表?

这是我到目前为止的代码。

def open_file():
      '''Remember the docstring'''
      Done = False
      while not Done: 
        try:
           file_name = input("Enter a filename: ") 
           file_pointer = open(file_name)
           Done = True
           return file_pointer

       except FileNotFoundError:
           print("File not found. Please try a different filename: ")

 def read_file(file_pointer):  
      ''' Remember the docstring'''
     # Read n and initizlize the network to have n empty lists -- 
     #    one empty list for each member of the network
     n = file_pointer.readline()
     n = int(n)
     network = []
     user_chosen = int(input("Please pick a number within the correct range: "))
     for user_chosen in range(n):
        network.append([])
     else:
       print("Error: input must be an int within the correct range.")
     return network 

0 个答案:

没有答案