python append list return none

前端 未结 1 2058
闹比i
闹比i 2020-12-22 14:14

I have the following code to generate a list of tuples:

list_of_tuples = list()

for name in list_of_names:
    temporary_list = [name]
    date = function_t         


        
相关标签:
1条回答
  • 2020-12-22 14:40

    You forgot to call the list() type:

    list_of_tuples = list()
    #    ----------------^ You didn't do this.
    

    Your exception (as posted in the comments) shows that you tried to call .append on the type object instead:

    >>> list.append(())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: descriptor 'append' requires a 'list' object but received a 'tuple'
    >>> list().append(())
    

    Better use [] to produce an empty list in any case:

    list_of_tuples = []
    
    0 讨论(0)
提交回复
热议问题