There is a list that still has lists. For example:

Date = ['Команда1', ['Даты', ['27-28.04.2019', '20.04.2019'], ['События',['Событие1', 'Событие2']]]] 

I know how to add a simple value to the Date list, but I don’t know how to stuff a value into the list that comes after the word "Dates".

How to write Date.append() correctly or what can be used instead? I tried Date.extend() , but this method breaks the string into characters and simply inserts them.

    2 answers 2

     Date[1].insert(1, 'XXXXXX') 

    or dynamically:

     Date[1].insert(Date[1].index('Даты') + 1, 'XXXXXX') 

    result:

     In [69]: Date Out[69]: ['Команда1', ['Даты', 'XXXXXX', ['27-28.04.2019', '20.04.2019'], ['События', ['Событие1', 'Событие2']]]] 

    UPDATE:

     In [80]: Date[1][Date[1].index('Даты')+1].append('11.11.2011') In [81]: Date Out[81]: ['Команда1', ['Даты', ['27-28.04.2019', '20.04.2019', '11.11.2011'], ['События', ['Событие1', 'Событие2']]]] 
    • And if, for example, where are the numbers? How to add? - V. Bychkov
    • @ V.Bychkov, what are the numbers? Do you mean dates? - MaxU
    • Yes. Sorry for not having - V. Bychkov

    Like this:

     Date[1].insert(2, "Значение") # Выведет: ['Команда1', ['Даты', ['27-28.04.2019', '20.04.2019'], 'Значение', ['События', ['Событие1', 'Событие2']]]] 

    To make it clearer:

     print(Date[1]) # Выведет: ['Даты', ['27-28.04.2019', '20.04.2019'], ['События', ['Событие1', 'Событие2']]] 

    The command Date [1] .insert (2, "Value") will insert "Value" at index 2, after ['27 -28.04.2019 ', '20 .04.2019']