Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101296 > unrolled thread

insert many numbers to a list, a second method.

Started by"飛飛" <benph@sina.com>
First post2016-01-05 21:36 +0800
Last post2016-01-05 21:36 +0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  insert many numbers to a list,  a second method. "飛飛" <benph@sina.com> - 2016-01-05 21:36 +0800

#101296 — insert many numbers to a list, a second method.

From"飛飛" <benph@sina.com>
Date2016-01-05 21:36 +0800
Subjectinsert many numbers to a list, a second method.
Message-ID<mailman.25.1452086288.2305.python-list@python.org>

--------------------------------
l = list(range(0,12))
numbers = [5,3,2,7]         #insert numbers at 5th position.
list1 = list(range(5,9))
list2 = list(range(0,5))
list2.extend(numbers)     #
for i in list1:
    l.insert(i,list2[i])
print(l)------>           l =  [0, 1, 2, 3, 4, 5, 3, 2, 7, 5, 6, 7, 8, 9, 10, 11]

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web