Tagged Questions
8
votes
1answer
270 views
Help me make my Python code clearer
Here's my solution to Project Euler problem 40.
import operator
import math
def levels(n):
return 9 * n * 10 ** (n - 1)
def face_value(i):
def level_filler(i):
n = 1
yield 1
...
6
votes
2answers
1k views
Generating all combinations and permutations of a set of symbols
I am new to Python and want to have a "pythonic" coding style from the very beginning. Following is a piece of codes I wrote to generate all combinations and permutations of a set of symbols, e.g. abc ...
4
votes
3answers
180 views
Alphabetizing `import` Statements
I did a quick google search, and it didn't show up.
I haven't noticed it posted in pylint.py, or PEP8.py.
My emacs mode doesn't warn me if my imports are listed arbitrarily...does anyone do this?
...
3
votes
1answer
142 views
Review for Python mapping container in which every element is a key
I wanted to have a python container in which every element is a key (like in a set), but still supports mapping (like a dict) between the elements.
To get a container which supports this idea the ...
3
votes
2answers
150 views
Becoming more pythonic
I started porting an API wrapper from java to python for practice. I am looking for ways to improve the readability/maintainability this code.
I have done some reading about "pythonic" style and I am ...
3
votes
2answers
117 views
Style comments please on my timer class, which I hope will be a pattern for other classes
I'm a relative noob to Python. On a range of 0 to 10, where 0 is a complete noob and 9 is Guido, I'd put myself as 1 aspiring to 2.
So I wanted a timer, rather like the Visual Basic object, and I ...
2
votes
2answers
169 views
What are the bad habits etc. in this code?
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? I think it will help me become a better coder.
# Alien Assualt
# A bullet ...
2
votes
2answers
59 views
How should I present long string literals (URLs) in Python?
I have a web scraping application that contains long string literals for the URLs. What would be the best way to present them (keeping in mind that I would like to adhere to PEP-8.
URL = ...
2
votes
1answer
199 views
PEG parser in Python
Any suggestions to make this code clearer, more Pythonic, or otherwise better? I'm open to changes to the design as well as the code (but probably won't drop features or error checking since ...
2
votes
1answer
106 views
Making my code look more Python-like
I've written a simple program in Python which does the following:
Input: an integer n
Output: a 2^n x 2^n matrix containing small Ls which fill the entire matrix except one single square. Each L has ...
2
votes
1answer
48 views
Performance and design question
I'm working on a web application using bottle, and it is, at this point, functional.
The gist of it is that i have a database of drinks, with associated IDs, and associated sets of ingredients. the ...
2
votes
1answer
233 views
Generating words based on a list of letter [Python]
I wrote a program to take a list of letters and from every permutation of them and check that against the dictionary and print out valid words. So constraints are that there is a control letter which ...
2
votes
2answers
100 views
Pythonic style guide
Which of these 3 python snippets is more pythonic?
This 1 liner list comprehensions which is a little overcomplex
users_to_sent = [(my_database.get_user_by_id(x), group['num_sent'][x]) for x in ...
2
votes
1answer
111 views
HNews “ask section” page scraping Python script
Here is a small script I wrote to get the HNews ask section and display them without using a web browser. Just looking for feed back on how to improve my style/coding logic/overall code.
...
1
vote
1answer
886 views
Dynamic programming solution to knapsack problem
I wrote a solution to the Knapsack problem in Python, using a bottom-up dynamic programming algorithm. It correctly computes the optimal value, given a list of items with values and weights, and a ...