Create a list of 100 integers whose value and index are the same, e.g. Show
Here is my code.
Veedrac 55.6k14 gold badges108 silver badges165 bronze badges asked Sep 26, 2013 at 3:49
2 Since nobody else
realised you're using Python 3, I'll point out that you should be doing answered Sep 26, 2013 at 4:22
VeedracVeedrac 55.6k14 gold badges108 silver badges165 bronze badges 2 Use range() for generating such a list
answered Sep 26, 2013 at 3:50
If you want to get a list of numbers
between 0-100, use
The answer to your question is pretty much
answered Sep 26, 2013 at 3:50
TerryATerryA 56.9k11 gold badges117 silver badges137 bronze badges You can use
Or you could do this recursively:
answered Sep 26, 2013 at 3:52
tom10tom10 64.6k9 gold badges122 silver badges134 bronze badges 1 Also can use List Comprehensions, like
answered Apr 30, 2018 at 12:58
If you want to import
Should work in python2.7 and python3.x answered Apr 28, 2018 at 18:07
double-beep 4,57613 gold badges30 silver badges40 bronze badges answered Apr 29, 2020 at 2:47
2 How do you create a list in numbers in Python?This article describes such approaches.. Using range. The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 ending at a specified number. ... . Using randrange. The random module can also generate a random number between in a similar way as above. ... . With numpy. arrange.. How do I make a list of 10 elements in Python?How do I create an empty list that can hold 10 elements? However, that gives IndexError: list assignment index out of range .. insert: list. insert(indexPosition, value). append: list. append(value). extend: list. extend(value). How do you create a range in a list in Python?# Create a list in a range of 10-20. My_list = [ range ( 10 , 20 , 1 )] # Print the list. print (My_list). # Create a list in a range of 10-20. My_list = [ * range ( 10 , 21 , 1 )] # Print the list. print (My_list). |