my code stock.com

- List of random numbers
- Insert to/ remove from list

Snippet options

Download: Download snippet as list-related.py.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

'''
List of random numbers
'''
import random
a = random.sample(range(100), 10) # 10 numbers, inclusive of 0 and 99. No repeat


'''
Insert to list
'''
var=7
list =[1,2,3,4,5,6]
list.insert(0,var)
# >>> [7, 1, 2, 3, 4, 5, 6]

# OR:
a = 5
li = [1, 2, 3]
[a] + li
# >>> [5, 1, 2, 3]


'''
Remove elements from list
'''
# By index
a = [1,2,3,4]
for i in range(len(a)):
    a.pop(0) # remove the elem AND return it
    del a[0] # simply remove the elem
print(a)
# By value
a.remove(2)

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.