Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag.

Filter by
Sorted by
Tagged with
2 votes
1 answer
3k views

Drawing a table in Python3 [closed]

I have created a module to draw text tables. The relevant parts are below and here's the full code for txtable). ...
user avatar
  • 123
-2 votes
1 answer
1k views

Best way to print the value of a variable? [closed]

Which of the following is better coding style and why? print("We have x = %i" %x) print("We have x = "+str(x))
user avatar
  • 1
5 votes
1 answer
455 views

Script for concatenating delimited text files

I need to concatenate a bunch of delimited text files. In the process, I need to add a new column to the data based on part of the name of one of the directories containing each file. The script works,...
user avatar
  • 151
3 votes
2 answers
6k views

Find scrambled words within word list

I'm just getting started with Python -- completing a simple exercise from a practice website. My code works -- just looking for feedback on better ways to achieve the goal. Goal: Find the ...
user avatar
2 votes
2 answers
1k views

How to make this random number game better?

I'm a newbie trying to teach myself Python. Could somebody tell me if there is a better way to write this? I am also curious as to whether or not there is anything I should not do. This code does ...
user avatar
0 votes
2 answers
674 views

How to enumerate the internal nodes and leaves of a tree more elegantly?

Might there be a simpler way to write this code? I'd like to learn to write code more efficiently. ...
user avatar
  • 161
2 votes
1 answer
124 views

How to turn this working A/B optimization program into more pythonic code?

I have a working solution for the given problem of A/B Optimization, but you as an experienced Python (3) developer will agree with me, that this solution is not very pythonic at all. My Question here ...
user avatar
6 votes
2 answers
10k views

Returning a list of the values from the binary tree

I want to return a list of the values from the binary tree. Is there a shorter and more efficient way to write the method for numbers? ...
user avatar
  • 161
14 votes
2 answers
9k views

Unbeatable Tic-Tac-Toe program seems difficult to read

I've made an unbeatable Tic-Tac-Toe in Python 3.3. While it truly was unbeatable, it was an eyesore to look at and nigh impossible to read. That code is here. I have since then optimized it for ...
user avatar
8 votes
1 answer
3k views

Subscriptable/Indexable generator

I'm not a Python developper, but I enjoy programming with it, and for a project I wanted to have generators that I can easily index. Using python's slice model is obviously the way to go, and here's ...
user avatar
2 votes
1 answer
71 views

Checking user input for boxing sim engine [closed]

I am creating a simple Boxing sim engine and have got things working fairly well. A few months ago I was instructed to avoid copy and pasting code and to try and "conserve my logic". Anyways, I feel ...
user avatar
  • 23
4 votes
3 answers
11k views

Rock, Paper, Scissors game assignment

This is an assignment that I have already turned in. It works great, but I was wondering if there are any flaws in the code, or how to write it in a more pythonic way. ...
user avatar
3 votes
1 answer
990 views

Object Composition

So I have this Pygame 3.3.2 code of 2 classes. I tried to make it as simpler as possible, but ofcourse to show the problems I have with thedesign. ...
user avatar
  • 359
4 votes
1 answer
217 views

Creating a game with rectangular shapes

I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to ...
user avatar
  • 359
5 votes
4 answers
11k views

Building a number pyramid

I have been working a number pyramid program. This is a question from Y. Daniel Laing's Introduction to programming using Python (which is based on Python 3.2). The question is from chapter 5, and it ...
user avatar
11 votes
6 answers
17k views

"Multi-key" dictionary

I was making a relatively large-scale project in Python as a learning experiment, and in the process I found that it would be useful to have a map (or, in Python, I guess they're called dictionaries) ...
user avatar
  • 4,859
4 votes
1 answer
650 views

Batch program to xcopy from host PC to remote destination with multi-processing

This is a batch program to xcopy from host PC to remote destination with multi-processing. Kepler, Python-3.x are my environment. ...
user avatar
5 votes
2 answers
10k views

Simple age converter

I want you to pick my code apart and give me some feedback on how I could make it better or more simple. In my opinion this is the best code I have written, being that I'm new to programming. The ...
user avatar
  • 311
3 votes
1 answer
1k views

Python infinite product generator

I have the code below to get an infinite generator of the products of an iterable (e.g. for the iterable "ABC" it should return A, B, C, AA, AB, AC, BA, BB, BC, CA, CB, CC, AAA, AAB, AAC etc. ...
user avatar
  • 133
3 votes
3 answers
45k views

Python calculator script

Are there any ways to make this calculator script for Python better or simpler? ...
user avatar
  • 311
1 vote
1 answer
14k views

Super simple spam program

x = int(input("Choose the number of times you want to spam. ")) y = input("What message do you want to spam? ") w = x + 1 for i in range(1,w): print(y) Any ...
user avatar
  • 311
6 votes
2 answers
1k views

Simple anagram game with names of colors

This is a very simple anagram game that plays only with names of colors. I tried to focus on code design. I also wanted it to support further updates. But, my ...
user avatar
  • 359
2 votes
1 answer
3k views

Automatically indent a whole block of text into str.format

I wondered if there was any better way of doing so. I had a hard time figuring it out (it seemed nobody else already tried to do so). ...
user avatar
  • 221
5 votes
1 answer
234 views

Review Python script for getting the stats of codereview.SE into a file for analysis

I wrote a script for getting the stats of codereview.SE from the front page into a file. Github link if someone prefers reading there. Here is data_file.txt's ...
user avatar
  • 2,269
3 votes
1 answer
352 views

Streamlining repetitive class definitions in python with a class_factory() function

I forked this repo to be more concise. The code is here. I'll paste it below since that seems to be the style. I removed the class definitions at the bottom that I didn't change -- the edit I'm ...
user avatar
2 votes
1 answer
387 views

How do I clean up these Python decorators?

I wrote some type checking decorators for Python. One checks the type that a function returns, the other checks the type that a function accepts. ...
user avatar
3 votes
1 answer
1k views

Command line calculus program

I have written a simple command line program in Python 3 that accepts a function (in the mathematical sense) from a user and then does various "calculus things" to it. I did it for my own purposes ...
user avatar
4 votes
1 answer
647 views

User-input prime number generator

What do you consider the readability of this program? Do you think it's easy to understand what the variables and functions do just by reading their names? Would you prefer more, less, or this amount ...
user avatar
4 votes
2 answers
21k views

Counting letters in a text file

As a beginner Python programmer, I wrote a simple program that counts how many times each letter appears in a text file. It works fine, but I'd like to know if it's possible to improve it. ...
user avatar
  • 307
-1 votes
1 answer
104 views

Find all subsets of a vector that sum up to another vector

I'm looking for a way to make my code more simple. This code takes a list of vectors and returns all subset of that list that sum up to another vector. For example: ...
user avatar
1 vote
2 answers
778 views

Efficient way of code reuse for finding the largest prime factor

I was doing timing with variations of function largest_prime_factor. I was able to write a better one largest_prime_factor2. ...
user avatar
  • 2,269
5 votes
2 answers
312 views

Using a monkey-patched XML parser to convert journal articles to ePub format

I am working on a project that involves XML parsing, and for the job I am using xml.dom.minidom. During development I identified several patterns of processing that I refactored into discrete methods. ...
user avatar
5 votes
2 answers
612 views

Finding words of a given length only using given letters

It's a (simple) guesser for game where you need to find words of a given length only using given letters. I'd like to know if there's a more pythonic way to do things here. ...
user avatar
5 votes
2 answers
7k views

Four-function calculator with roots and powers

I have some code for a calculator, and I was wondering what I could look at to make the code smaller, easier to read or better in any way. I'm particularly looking at my global variable ...
user avatar
  • 51
5 votes
1 answer
290 views

Accelerate OpenGL 2D on Python3

I'm using OpenGL to draw about 20 circles. Each circle has 2 lines, ~10 segments, and all of them have different colors and lengths. Frames per Second are around 4. How can I optimize this to run ...
user avatar
5 votes
5 answers
3k views

Guessing words from scrambled letters

How could I possibly shorten / clean this up? I suppose mainly clean up the loop at the start asking whether they would like to scramble the code. ...
user avatar
  • 177
6 votes
3 answers
5k views

Hangman in Python

I created this version of Hangman in Python 3. Does anyone have any tips for optimization or improvement? ...
user avatar
  • 1,291
4 votes
1 answer
4k views

Finding sub-list

Pythonic way of expressing the simple problem: Tell if the list needle is sublist of haystack ...
user avatar
  • 257
3 votes
2 answers
1k views

Alien Assault game

I know this code is pretty awful, but, by any chance, could someone point out all the flaws you can find and tell me them? It's Python 3.2.3, by the way. ...
user avatar
3 votes
1 answer
213 views

Package Manager in Python

I've written a package manager for OS X in order to improve my Python skills. This is the second programming project I've ever worked on, so I do not expect it to be great, or anything, but I would ...
user avatar
2 votes
2 answers
1k views

Python memoization decorator

I have spent all night whipping up this recipe. It's my first Python decorator. I feel like I have a full understanding of how decorators work now and I think I came up with a good object-oriented ...
user avatar
3 votes
2 answers
3k views

Simplifying working Caesar cipher

I'm learning Python 3 at the moment, so to test the skills I've learned, I am trying the puzzles at Python Challenge. I've created some code to solve the 2nd puzzle here. it works, but I think that ...
user avatar
3 votes
2 answers
2k views

Improving and optimizing Tic-Tac-Toe game written in Python 3

I've been teaching myself Python3 for about a week now and I decided to put my skills to the test by writing a simple Tic-Tac-Toe game. Here is what I came up with: ...
user avatar
  • 141
3 votes
1 answer
3k views

Collections.Counter in Python3

Can you suggest how I might make the following code more efficient: ...
user avatar
  • 263
11 votes
4 answers
2k views

Generating the sequence of the digits that appear in the sequence of natural numbers

This is a revisit to a question already asked here about a year and a half ago. Project Euler's Problem 40 involves generating the sequence of digits that appear in the natural numbers, all ...
user avatar
  • 213

1
98 99 100 101
102