[Python] вопрос/ответ.

Discussion in 'Python' started by De-visible, 21 Jan 2009.

  1. Matrix001

    Matrix001 Member

    Joined:
    18 Aug 2016
    Messages:
    88
    Likes Received:
    22
    Reputations:
    0
    Спасибо большое !
     
  2. Matrix001

    Matrix001 Member

    Joined:
    18 Aug 2016
    Messages:
    88
    Likes Received:
    22
    Reputations:
    0
    Еще, кто может помогите. Есть массив содержащий в себе допустим 10 массивов, то есть -> arr = [[], [], [], [], [], [] ,[], [], [], []] в каждый массив запихнули по цифрам, то есть вот такое получается -> arr = [[1, 1, 1, 1], [2, 2, 2], [3, 3, 3, 3, 3], [4], [5, 5], [6, 6, 6] ,[7, 7, 7], [8, 8, 8, 8, 8, 8, 8, 8], [9, 9, 9], [10]]. Нужен алгоритм который это все дело нормализует в такой вид arr = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9], [10, 10 10]]
     
  3. aka dexter

    aka dexter Elder - Старейшина

    Joined:
    23 Jun 2006
    Messages:
    528
    Likes Received:
    603
    Reputations:
    74
    Code:
    arr = [[1, 1, 1, 1], [2, 2, 2], [3, 3, 3, 3, 3], [4], [5, 5], [6, 6, 6] ,[7, 7, 7], [8, 8, 8, 8, 8, 8, 8, 8], [9, 9, 9], [10]]
    final=[]
    
    for i in arr:
        i = [i[0]] * 3
        final.append(i)
    print(final)
    
     
    Turanchocks_ likes this.
  4. Matrix001

    Matrix001 Member

    Joined:
    18 Aug 2016
    Messages:
    88
    Likes Received:
    22
    Reputations:
    0
    Да, казалось бы так просто, но мне надо именно с помощью перемещения. То есть в массиве будет не [1, 1, 1, 1] там будет список [(1, 2), (1, 1), (1, 4), (1, 5)] и так в каждом !!!
     
  5. aka dexter

    aka dexter Elder - Старейшина

    Joined:
    23 Jun 2006
    Messages:
    528
    Likes Received:
    603
    Reputations:
    74
    ок, а теперь адекватно поставь задачу...
    допустим... [(1, 2), (1, 1), (1, 4), (1, 5)]
    и че, должно быть на выходе... [1,1], [1], [1, 1, 1, 1], [1, 1, 1, 1, 1]) ???
     
    Jerri likes this.
  6. Jerri

    Jerri Level 8

    Joined:
    12 Jul 2009
    Messages:
    133
    Likes Received:
    358
    Reputations:
    22
    Code:
    arr = [[1, 1, 1, 1], [2, 2, 2], [3, 3, 3, 3, 3], [4], [5, 5], [6, 6, 6] ,[7, 7, 7], [8, 8, 8, 8, 8, 8, 8, 8], [9, 9, 9], [10]]
    arr.sort()
    
    def normalize(item):
        return [item[0], item[0], item[0]]
    
    result = list(map(normalize, arr))
    print(result)
    <<< [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9], [10, 10, 10]]
    
    Такие ТЗ - страшный сон всех программистов. :)
     
    Turanchocks_, Pirnazar and aka dexter like this.
  7. Matrix001

    Matrix001 Member

    Joined:
    18 Aug 2016
    Messages:
    88
    Likes Received:
    22
    Reputations:
    0
    Короче, походу это стало сверх-секретным проектом)
     
Loading...
Similar Threads - Python вопрос ответ
  1. f0b0s
    Replies:
    1
    Views:
    627