Latest questions in Python

0 votes
1 answer

More Pythonic way of counting things in a heavily nested defaultdict

You can try the following, this might ...READ MORE

Jun 20, 2019 in Python by SDeb
• 13,300 points
1,148 views
0 votes
1 answer

How to expose std::pair to python using boost::python?

The most simple example of exposing std::pair is: class_<std::pair<int, int> ...READ MORE

Jun 20, 2019 in Python by SDeb
• 13,300 points
1,093 views
0 votes
1 answer

Change the window background color using turtle - python

Try this: import turtle #set up the screen wn = ...READ MORE

Jun 19, 2019 in Python by Faiza
16,073 views
0 votes
1 answer

Change the snake head color using python turtle

You can et the snakehead color by ...READ MORE

Jun 19, 2019 in Python by Faiza
1,703 views
0 votes
0 answers

How can i perform rounding off a decimal number in python?

Can you provide the code for this? READ MORE

Jun 19, 2019 in Python by Waseem
• 4,540 points
409 views
0 votes
0 answers

How do you implement insertion sort in python?

Can you give the sample code as ...READ MORE

Jun 19, 2019 in Python by Waseem
• 4,540 points
517 views
0 votes
1 answer

Snake head now showing when trying to build the snake game using python module turtle

Hey @Nagya, so you added the following ...READ MORE

Jun 19, 2019 in Python by Faiza
1,077 views
+1 vote
3 answers

Python error "AttributeError: 'Turtle' object has no attribute 'Shape'"

Hey @Nagya, replace python.Shape("Square") with the following: python.shape("square") Python is case ...READ MORE

Jun 19, 2019 in Python by Faiza
21,091 views
0 votes
1 answer

Python error "AttributeError: '_Screen' object has no attribute 'mainloop'" python module turtle

Hey @Nagya, replace  wn.mainlopp() with turtle.mainloop() ...READ MORE

Jun 19, 2019 in Python by Faiza
6,526 views
0 votes
1 answer

Why are Python lambdas useful?

The main purpose of anonymous functions come ...READ MORE

Jun 19, 2019 in Python by Wajiha
• 1,950 points
650 views
0 votes
1 answer

What happens when you use lambda inside lambda?

Yes you can use lambda inside lambda. ...READ MORE

Jun 19, 2019 in Python by Wajiha
• 1,950 points
1,930 views
0 votes
1 answer

Python error "ValueError: size needs to be (int width, int height)" while using pygame.Surface

pygame.Surface takes in integer values for building ...READ MORE

Jun 19, 2019 in Python by Varsha
5,252 views
+1 vote
1 answer

Python error "pygame.error: Couldn't open pygame.png"

icon = pygame.image.load('spaceship.png') pygame.error: Couldn't open spaceship.png I am ...READ MORE

Apr 9, 2020 in Python by Ali
10,124 views
0 votes
1 answer

Where is builtins module located?

The module is built-in to the python ...READ MORE

Jun 19, 2019 in Python by SDeb
• 13,300 points
894 views
0 votes
1 answer

Combine selector conditions

In a nutshell, you can do: A[:, range(3) ...READ MORE

Jun 19, 2019 in Python by SDeb
• 13,300 points
491 views
0 votes
2 answers

Python error "pygame.error: Couldn't open pygame.png"

add import os at top of your ...READ MORE

Sep 25, 2020 in Python by anonymous
1,423 views
0 votes
1 answer

Package installed but still says "ImportError: No module named pygame.locals"

So Harsha, you Import the module first ...READ MORE

Jun 18, 2019 in Python by Varsha
3,652 views
0 votes
1 answer

Python error "ImportError: No module named pygame.locals"

You need to download and install the ...READ MORE

Jun 18, 2019 in Python by Greg
6,260 views
0 votes
0 answers

How can we read a text file in a list in python?

Can you give the sample code as ...READ MORE

Jun 18, 2019 in Python by Waseem
• 4,540 points
375 views
0 votes
0 answers

How can you print the date in a regular format in python?

Is there a module or package in ...READ MORE

Jun 18, 2019 in Python by Waseem
• 4,540 points
324 views
0 votes
1 answer

How to synchronize python lists?

threading provides Lock objects if you need to protect an ...READ MORE

Jun 18, 2019 in Python by SDeb
• 13,300 points
1,393 views
0 votes
1 answer

Get bbox in data coordinates in matplotlib

I'm not sure how you got the ...READ MORE

Jun 18, 2019 in Python by SDeb
• 13,300 points
4,493 views
0 votes
1 answer

Python function to find a list of all keywords

You can use the keyword module for ...READ MORE

Jun 17, 2019 in Python by Ayman
8,624 views
0 votes
1 answer

Python function to check if a given string is a keyword

You can get the list of keywords ...READ MORE

Jun 17, 2019 in Python by Drishya
1,961 views
0 votes
1 answer

python code to find if an array is monotonic

Hey Harsha, try out this code: def monotonic(a): ...READ MORE

Jun 17, 2019 in Python by Yesha
2,199 views
0 votes
1 answer

Python Error saying "NameError: global name 'true' is not defined"

It's a very small mistake. Change true ...READ MORE

Jun 17, 2019 in Python by Vinayak

edited Oct 7, 2021 by Sarfaraz 15,587 views
0 votes
1 answer

What does the map() method do in Python?

The map() function in Python is a ...READ MORE

Jun 17, 2019 in Python by anonymous
600 views
0 votes
1 answer

Using lambda functions to solve Algebra

Python lambda functions can be used to ...READ MORE

Jun 17, 2019 in Python by anonymous
2,648 views
0 votes
0 answers

What does a ternary conditional operator do in python?

Can you give an example using a ...READ MORE

Jun 17, 2019 in Python by Waseem
• 4,540 points
523 views
0 votes
0 answers

Does python support encapsulation?

If it does, how is it any ...READ MORE

Jun 17, 2019 in Python by Waseem
• 4,540 points
564 views
0 votes
2 answers

Check if there exists two elements in the array whose sum is equal to the sum of the entire array

You can try something like this Harsh: def ...READ MORE

Jun 17, 2019 in Python by Ayman
3,330 views
0 votes
0 answers

Python error "IndexError: list index out of range"

I am trying to execute the following ...READ MORE

Jun 17, 2019 in Python by Alok
7,224 views
+1 vote
2 answers

Python error "Python: can't assign to literal"

The way you're assigning variables is not ...READ MORE

Jun 17, 2019 in Python by Priya
15,086 views
+1 vote
9 answers

Python error "IndentationError: expected an indented block"

Python requires its code to be indented ...READ MORE

Jun 17, 2019 in Python by Varun

edited Jun 17, 2019 321,370 views
0 votes
1 answer

Reconstruct an array by replacing every element with a[[i-1]%K] - Python

Hey varsha, Have a look at this ...READ MORE

Jun 14, 2019 in Python by Miya
1,175 views
0 votes
0 answers

How can I find the files and skip the directories using os.listdir in python?

When I am using os.listdir I am ...READ MORE

Jun 14, 2019 in Python by Waseem
• 4,540 points
572 views
0 votes
0 answers

What is the procedure to list all the files in the directory?

How am i supposed list all the ...READ MORE

Jun 14, 2019 in Python by Waseem
• 4,540 points
316 views
0 votes
1 answer

Length and dimensions of NumPy arrays

The length of NumPy arrays can be ...READ MORE

Jun 14, 2019 in Python by Wajiha
• 1,950 points
1,076 views
0 votes
1 answer

How to check if a website allows web scraping?

To check if a website allows web ...READ MORE

Jun 14, 2019 in Python by Wajiha
• 1,950 points
15,735 views
0 votes
1 answer

Python array multiply

When you multiply a sequence by X in Python, ...READ MORE

Jun 14, 2019 in Python by SDeb
• 13,300 points
3,151 views
0 votes
1 answer

How to fill a list?

Consider the usage of extend: >>> l = [] >>> ...READ MORE

Jun 14, 2019 in Python by SDeb
• 13,300 points
475 views
0 votes
1 answer

Error while converting a list into a numpy array

The only possible reason I could think ...READ MORE

Jun 14, 2019 in Python by Rhea
2,408 views
0 votes
1 answer

Python Error ""ValueError: could not broadcast input array from shape (4) into shape (1000)""

There are better ways of achieving the ...READ MORE

Jun 14, 2019 in Python by Faiza
29,725 views
0 votes
0 answers

How does function definition work in python?

Is it same as other programming languages ...READ MORE

Jun 13, 2019 in Python by Waseem
• 4,540 points
381 views
0 votes
0 answers

How can you preserve timezone information in python?

What is the use of strfttime()  and ...READ MORE

Jun 13, 2019 in Python by Waseem
• 4,540 points
332 views
0 votes
1 answer

Information about functions or classes in Python

Information about functions, classes, modules, etc can ...READ MORE

Jun 13, 2019 in Python by Nisa
• 1,090 points
492 views
0 votes
1 answer

Low precision and high recall application - Logical regression

In situations where you wish to reduce ...READ MORE

Jun 13, 2019 in Python by Meg
2,638 views
0 votes
1 answer

High Precision value and low recall value - Logistic regression

You use high positive and low recall ...READ MORE

Jun 13, 2019 in Python by Greg
1,618 views
0 votes
2 answers

Python Error "UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)"

import csv import sys reload(sys) sys.setdefaultencoding('utf8') data = [["a", "b", u'\xe9']] with ...READ MORE

Jun 28, 2019 in Python by anonymous
13,315 views
0 votes
1 answer

Python error "pandas.errors.ParserError: Error tokenizing data"

Pandas do not take .xlsx files. Rename ...READ MORE

Jun 13, 2019 in Python by Rhea
18,736 views