I recently just learned how to do this without using loops:


import random
x = [0 for _ in range(10)] #underscore used when you do not need the value from the list. So here 0 replaces the value from range(10)
#expected out put [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

y = [random.random() for _ in range(20)] #similar logic here, but instead of a known value like 0, the method random generates a random value
z = [random.randrange(10) for _ in range(10)] #if you want the values to be within a specific range 0 - 10
a = [random.randrange(12, 20) for _ in range(10)]#if you want the values to be within a specific range 12 - 20

That is all I know for now. I will update this when I find new and more efficient methods…

Check out

Python: Matplotlib – How to use csv and subplots for beginners

python: Creating a simple bar plot with python, matplotlib module and csv data

Please follow and like us:
0

Enjoy this blog? Please spread the word :)

error: Content is protected !!