“Wydrukuj losowy ciąg z listy Python” Kod odpowiedzi

Wydrukuj losowy ciąg z listy Python

import random

list = ["Item 1", "Item 2", "Item 3"]			# List
item = random.choice(list)						# Chooses from list
print(item)					# Prints choice

# From stackoverflow
# Tried and tested method
Fair Finch

Jak wydrukować losową część listy w Python

import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))
Careful Caracal

losowy picker w Python

import random
#dictionary
x_dict = {30:60, 20:40,10:20}
key = random.choice(list(x_dict))
print (key)#if you want it to print 30, 20, or 10
print (x_dict[key])#if you want it to print 60, 40, or 20
print (key,"-", x_dict[key])# if you want to print 30 - 60, 20-40,or 10-20
HelloWorld

Wybierz wartość losową z listy Python

import random

# with replacement = same item CAN be chosen more than once.
# without replacement = same item CANNOT be chosen more then once.

# Randomly select 2 elements from list without replacement and return a list
random.sample(list_name, 2)

# Randomly select 3 elements from list with replacement and return a list
random.choices(set_name, k=3)

# Returns 1 random element from list
random.choice(list_name)
CodeHelper

Wydrukuj losowy ciąg z listy Python

Banana
Car
Mobile
Super Sandpiper

Odpowiedzi podobne do “Wydrukuj losowy ciąg z listy Python”

Pytania podobne do “Wydrukuj losowy ciąg z listy Python”

Więcej pokrewnych odpowiedzi na “Wydrukuj losowy ciąg z listy Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu