Resources
Answers
Examples
Sign in
Get Started
What do you want to save?
Add Code snippet
New code examples
Python
2021-10-13 09:08:04
how to import a variable from another python file
from vardata import verb_list, other_list import random print random.choice(verb_list)
Add solution
Python
2021-10-13 02:04:05
python random liste
import random liste = ["world, HELLO !", "hello world !"] N = random.choice(liste) print(N)
Add solution
Python
2021-10-11 23:18:03
get random line from file python
import random lines = open('file.txt').read().splitlines() # creates a list with one line per iteù randomLine =random.choice(lines) # pick up a random item in this list
Add solution
Python
2021-10-11 22:26:05
markov chain python code
import numpy as np class MarkovChain(object): def __init__(self, transition_prob): """ Initialize the MarkovChain instance. Parameters ---------- transition_prob: dict A dict object represen...
Add solution
Python
2021-10-07 06:36:04
random pick any file from directory python
import os, random random.choice(os.listdir("C:\\")) #change dir name to whatever
Add solution
Python
2021-10-06 13:36:05
python flip a coin
import random result = random.choice(["Heads","Tails"])
Add solution
Python
2021-10-05 04:50:05
python choose random sample from list
import random #1.A single element random.choice(list) #2.Multiple elements with replacement random.choices(list, k = 4) #3.Multiple elements without replacement random.sample(list, 4)
Add solution
Other
2021-10-04 18:10:03
rondom choise from list
import random foo = ['a', 'b', 'c', 'd', 'e'] print(random.choice(foo))
Add solution
Python
2021-10-04 14:47:05
numpy random for string
fruits = ['apple', 'banana', 'orange', 'grape'] subset_size = int(0.7 * len(fruits)) np.random.choice(fruits, subset_size, replace=False) # array(['grape', 'banana'], dtype='<U6')
Add solution
Other
2021-10-03 07:39:06
pythons os module choose random file
import os import random import dircache dir = 'some/directory' filename = random.choice(dircache.listdir(dir)) path = os.path.join(dir, filename)
Add solution
‹
1
2
3
4
5
6
7
8
›
Best helpers
daily
weekly
monthly
for 3 months
Ranking is empty
This website uses cookies to make IQCode work for you. By using this site, you agree to our
cookie policy
Welcome Back!
Sign up to unlock all of IQCode features:
Test your skills and track progress
Engage in comprehensive interactive courses
Commit to daily skill-enhancing challenges
Solve practical, real-world issues
Share your insights and learnings
Sign in
E-mail
Password
Recover lost password
Log in
Or log in with
Not registered?
Sign up takes less than a minute
Create a Free Account
Sign up to unlock all of IQCode features:
Test your skills and track progress
Engage in comprehensive interactive courses
Commit to daily skill-enhancing challenges
Solve practical, real-world issues
Share your insights and learnings
Sign up
Email
Password
Sign up for free
Or sign up with
By signing up, you agree to the
Terms and Conditions
and
Privacy Policy
. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.