Skip to content

Tag: python

Use curly braces to initialize a Set in Python

I’m learning python, and I have a novice question about initializing sets. Through testing, I’ve discovered that a set can be initialized like so: Are there any disadvantages of doing it this way, as opposed to the standard way of: or is it just a question of style? Answer There are two obvious is…

Playing a wavefile from the html using flask framework?

This is my run.py code This my base.html file this my tasks.html This my s1.html In the s1.html i have a hyperlink to a audio wav file . I want to play the audio file from the s1.html. The wav file is present in the root directory. It is throwing error GET /ps.wav HTTP/1.1″ 404 Please tell how to solve

Global variables in recursion. Python

OK, i’m using Python 2.7.3 and here is my code: I’m trying to modify the variable count inside the leng function. Here are the things that I’ve tried: If I put the variable count outside the lenRecur function it works fine the first time, but if I try again without restarting python shell, t…

Minimal stone piles

Question: You are given a list of integer weights. You need to distribute these weights into two sets, such that the difference between the total weight of each set is as low as possible. Input data: A list of the weights. Output data: A number representing the lowest possible weight difference. I saw an answ…

Multiple try codes in one block

I have a problem with my code in the try block. To make it easy this is my code: Is something like this possible? Answer You’ll have to make this separate try blocks: This assumes you want to run code c only if code b failed. If you need to run code c regardless, you need to put the try

Split a large pandas dataframe

I have a large dataframe with 423244 lines. I want to split this in to 4. I tried the following code which gave an error? ValueError: array split does not result in an equal division How to split this dataframe in to 4 groups? Answer Use np.array_split:

Check whether string is in CSV

I want to search a CSV file and print either True or False, depending on whether or not I found the string. However, I’m running into the problem whereby it will return a false positive if it finds the string embedded in a larger string of text. E.g.: It will return True if string is foo and the term fo…