756 Answered Questions for the topic Python
04/30/19
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
In the following method definitions, what does the `*` and `**` do for `param2`? def foo(param1, *param2): def bar(param1, **param2):
04/30/19
How to put the legend out of the plot?
I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure...
more
How to lowercase a string in Python?
Is there a way to convert a string from uppercase, or even part uppercase to lowercase? E.g. Kilometers --> kilometers.
04/28/19
list comprehension vs. lambda + filter?
I happened to find myself having a basic filtering need: I have a list and I have to filter it by an attribute of the items.My code looked like this: my_list = [x for x in my_list if x.attribute...
more
04/27/19
How can I sort a dictionary by key?
What would be a nice way to go from `{2:3, 1:89, 4:5, 3:0}` to `{1:89, 2:3, 3:0, 4:5}`? I checked some posts but they all use the "sorted" operator that returns tuples.
Python Microsoft Powerpoint
04/27/19
Make a PowerPoint presentation using Python?
So I have a collection of close to 90 photographs along with a caption and the date stored in a text file. The images are of variable sizes and I would like to automate the procedure of converting...
more
Python List
04/27/19
How to get the number of elements in a list in Python?
items = [] items.append("apple") items.append("orange") items.append("banana") # FAKE METHOD:: items.amount() # Should return 3How do I get the number of elements in the list?
04/24/19
Manually raising (throwing) an exception in Python?
How can I raise an exception in Python so that it can later be caught via an `except` block?
Python Microsoft Powerpoint
04/23/19
How to convert a .pptx to .pdf using Python?
I have been looking to convert a .pptx file to a .pdf file through a Python script for several hours but nothing seems to be working.
**What I have tried:** I have tried 1) [this script][1] which...
more
04/20/19
How do I install pip on Windows?
[`pip`](https://pip.pypa.io/en/stable/) is a replacement for [`easy_install`](http://setuptools.readthedocs.io/en/latest/easy_install.html). But should I install `pip` using `easy_install` on...
more
Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?
It seems to me like the files run the same without that line.
Python Static Methods
04/19/19
Static methods in Python?
Is it possible to have static methods in Python so I can call them without initializing a class, like: ClassName.StaticMethod ( )
Delete column from pandas DataFrame?
When deleting a column in a DataFrame I use: del df['column_name']And this works great. Why can't I use the following? del df.column_name*As you can access the column/Series as...
more
Python List
04/19/19
Is there a simple way to delete a list element by value?
a=[1,2,3,4] b=a.index(6) del a[b] print aThe above shows the following error:<!-- language: lang-none --> Traceback (most recent call last): File "D:\\zjm_code\\a.py", line...
more
Python
04/19/19
Checking whether a variable is an integer or not?
How do I check whether a variable is an integer?
04/18/19
How can I represent an 'Enum' in Python?
I'm mainly a C# developer, but I'm currently working on a project in Python.How can I represent the equivalent of an Enum in Python?
04/16/19
Convert two lists into a dictionary in Python?
Imagine that you have: keys = ['name', 'age', 'food'] values = ['Monty', 42, 'spam']What is the simplest way to produce the following dictionary? a_dict = {'name' : 'Monty', 'age' : 42,...
more
04/16/19
Understanding Python super() with __init__() methods?
I'm trying to understand the use of `super()`. From the looks of it, both child classes can be created, just fine. I'm curious to know about the actual difference between the following 2 child...
more
Python Logic
04/16/19
How to do while loops with multiple conditions?
I have a while loop in python
condition1=False
condition1=False
val = -1
while condition1==False and condition2==False and val==-1:
val,something1,something2 = getstuff()
if...
more
How can I make a time delay in Python?
I would like to know how to put a time delay in a Python script.
04/14/19
How do I copy a file in Python?
How do I copy a file in Python?I couldn't find anything under [`os`](https://docs.python.org/2/library/os.html).
Dynamically evaluating simple boolean logic in Python?
I've got some dynamically-generated boolean logic expressions, like:
* (A or B) and (C or D)
* A or (A and B)
* A
* _empty - evaluates to True_
The placeholders get replaced with booleans. Should...
more
Python
04/11/19
Hi, I need help with a program I am working on. This is the question?
How would I write a Python program that inputs a string of characters which represent a vanity telephone number, e.g., 800-MYPYTHON, and prints the all numeric equivalent, 800-69798466. You should...
more
Python Statistics
04/10/19
Python Programming and Statistics
In the winter season in the United States it is estimated that 30% of the population contracts respiratory diseases. If a sample of 350 people is taken, using Normal approximation to the binomiala)...
more
Python Disjoint Set Forest
04/08/19
PYTHON LANGUAGE
Write a function that receives a disjoint set forest S and prints the number of sets encoded byS and the size of the largest set in S.
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.