Python error "IndexError: Cannot choose from an empty sequence"

0 votes

I'm getting the following python error while using the random module:

 File "C:\Python33\lib\random.", line 250, in choice
    raise IndexError('Cannot choose from an empty sequence')
IndexError: Cannot choose from an empty sequence

How do I get rid of it?

Jul 5, 2019 in Python by Isha
440 views

1 answer to this question.

0 votes

Hi @Isha, According to your error 

 File "C:\Python33\lib\random.", line 250, in choice
    raise IndexError('Cannot choose from an empty sequence')
IndexError: Cannot choose from an empty sequence

Your file name seems to be random. Random is a module and can not be used as a file name. 

Change the filename and you should be fine.

answered Jul 5, 2019 by Patric

Related Questions In Python

0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
130 views
0 votes
1 answer

Create an empty list in python with certain size

Try this instead: lst = [None] * 10 The ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,390 points
2,379 views
0 votes
1 answer

Creating an empty list in Python

Here is how you can test which ...READ MORE

answered Aug 17, 2018 in Python by Priyaj
• 57,490 points
117 views
+1 vote
1 answer

How to print an error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Aug 23, 2018 in Python by Priyaj
• 57,490 points
376 views
+1 vote
3 answers

What are the ways of detecting outliners in Python

code from http://eurekastatistics.com/using-the-median-absolute-deviation-to-find-outliers  This uses the L1 distance ...READ MORE

answered Aug 24, 2018 in Python by eatcodesleeprepeat
• 4,750 points

reshown Aug 24, 2018 by Priyaj 100 views
0 votes
1 answer
0 votes
1 answer

How to create Pandas series from numpy array?

Hi. Refer to the below command: import pandas ...READ MORE

answered Apr 1, 2019 in Python by Pavan
333 views
0 votes
1 answer

How can I print an Error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Oct 12, 2018 in Python by Aryya
• 7,340 points
75 views
0 votes
1 answer

Can we access Outer class member from an Inner class in Python?

If you want to access outer class ...READ MORE

answered Feb 12, 2019 in Python by Omkar
• 68,860 points
1,904 views