Random selections from list

0 votes
How do you randomly draw an item from a list?
Jul 20, 2018 in Python by kaalabilli
• 1,090 points
15 views

1 answer to this question.

0 votes

Use random.choice()

foo = ['a', 'b', 'c', 'd', 'e']
number  = random.choice(foo)
answered Jul 20, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
2 answers

Pick a random item from the list - Python

You can also use secrets.choice() import secrets list = ...READ MORE

answered May 28 in Python by Kim
13 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
557 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 56,160 points
341 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 56,160 points
57 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 135 views
+4 votes
6 answers
0 votes
1 answer

List of lines from a file

with open(fname) as f: ...READ MORE

answered Apr 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
20 views
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
3,120 views