## Calculator using variable names

I’ve recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions. The question is here: Jimmy has invented a new kind of calculator that works with words rather than numbers. Input … Read more

## Reversing a number

I was working through a programming challenge I found on Reddit and it seemed easy enough: Find all numbers less than \\$10^n\\$ where the number and its reverse (the reverse of \\$123\\$ is \\$321\\$) are both divisible by \\$7\\$ and then sum them all together. def challenge_229(power): numbers = [] for x in range(0, 10**power, … Read more

## Removing entries from a dictionary containing bad words

I have a dictionary with each item containing a quote in another dictionary: { ‘example1’: {‘quote’: ‘And it must follow, as the night the day, thou canst not then be false to any man.\n’}, ‘example2’: {‘quote’: ‘What a piece of work is man! how noble in reason!.\n’} } I need to completely remove each entry … Read more

## Zipping two lists with an offset in Python

Walking my first steps in Python from C, I find myself missing pointers from time to time. In this case I want to go through a list processing two element at a time, where those elements are step places away. This is my initial approach, but I would be happy to learn a couple alternatives, … Read more

## Python: pass “mutable integer” in recursion

I’m working on some code to find the max depth/height in a tree. I came up with a recursive solution, and I find myself needing to pass an integer “by reference”. Currently, I’m using a mutable container to achieve this, but is there a more Pythonic way? class Node: “”” Node in a tree, with … Read more

## Brute Force generator

I just wrote a little Python 3 program to spit out every possible combination of a set of 99 characters. It gets the job done, but I would be very interested in what you think of it. I am just a few days into Python, so I would be grateful for even seemingly obvious advice. … Read more

## How do I use TensorFlow GPU?

How do I use TensorFlow GPU version instead of CPU version in Python 3.6 x64? import tensorflow as tf Python is using my CPU for calculations. I can notice it because I have an error: Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 I have installed tensorflow and tensorflow-gpu. … Read more

## Python send UDP packet

I am trying to write a program to send UDP packets, as in https://wiki.python.org/moin/UdpCommunication The code appears to be in Python 2: import socket UDP_IP = “127.0.0.1” UDP_PORT = 5005 MESSAGE = “Hello, World!” print “UDP target IP:”, UDP_IP print “UDP target port:”, UDP_PORT print “message:”, MESSAGE sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP … Read more

## Is there something similar to ‘rake routes’ in django? [duplicate]

This question already has answers here: Determine complete Django url configuration (10 answers) Closed 6 years ago. In rails, on can show the active routes with rake (http://guides.rubyonrails.org/routing.html): \$ rake routes users GET /users {:controller=>”users”, :action=>”index”} formatted_users GET /users.:format {:controller=>”users”, :action=>”index”} POST /users {:controller=>”users”, :action=>”create”} POST /users.:format {:controller=>”users”, :action=>”create”} Is there a similar tool/command for … Read more

## Form sending error, Flask

There is form with two <input type=”submit”>. But when i’m sending it, second submit causes error. layout: <form action=”{{ url_for(‘index’) }}” method=”post”> <input type=”submit” name=”add” value=”Like”> <input type=”submit” name=”remove” value=”Dislike”> </form> main.py: … if request.method == ‘POST’: if request.form[‘add’]: return redirect(url_for(‘index’)) elif request.form[‘remove’]: return redirect(url_for(‘index’)) … First submit(add) works well, but second(remove)…: Bad Request The … Read more