What do you want to save?
Add Code snippet
New code examples
-
Python 2022-03-25 00:40:03
reset shuffed array python
import random class Solution(object): def __init__(self, nums): self.original = [x for x in nums] self.temp = nums self.indices = [x for x in range(len(nums))] def re... Add solution -
Python 2022-03-13 11:35:06
generate random string python
import random import string def random_string_generator(str_size, allowed_chars): return ''.join(random.choice(allowed_chars) for x in range(str_size)) chars = string.ascii_letters + string.punctuation size = 12 print(chars) print('Random String of... Add solution -
Python 2022-03-13 00:45:08
guess the word python
import random # Put words to guess inside the array words = [] word = random.choice(words) n = len(word) print("Guess the word") guesses = '' #number of turn is equal to the legnth of the word stored in 'n' turns = n while turns > 0... Add solution -
-
Python 2022-02-12 01:10:15
snake water gun game in python
# Snake water gun game in python ''' Snake vs. Water: Snake drinks the water hence wins. Water vs. Gun: The gun will drown in water, hence a point for water Gun vs. Snake: Gun will kill the snake and win. In situations where both players choose the same ... Add solution -
Python 2022-02-11 23:15:26
R sample() funciton in python
import numpy as np np.random.choice(values, size=1000, replace=True, p=probability) # values is the input values that correspond to the weights # size is the number of samples to generate # Replace specifies if it's with or without replacement # p is t... Add solution -
Python 2022-02-06 20:00:24
pandas read_csv random rows
import pandas as pd import numpy as np filename = 'hugedatafile.csv' nlinesfile = 10000000 nlinesrandomsample = 10000 lines2skip = np.random.choice(np.arange(1,nlinesfile+1), (nlinesfile-nlinesrandomsample), replace=False) df = pd.read_csv(filename, skip... Add solution -
Python 2022-01-26 07:30:09
poisson disc python
import numpy as np import matplotlib.pyplot as plt # Choose up to k points around each reference point as candidates for a new # sample point k = 30 # Minimum distance between samples r = 1.7 width, height = 60, 45 # Cell side length a = r/np.sqrt(2) ... Add solution