Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.
4
votes
Easiest way to implement cycle crossover
Docstrings
You should include a docstring at the beginning of every method, class, and module you write. It allows anyone to view how to use and implement your method, using your_function_name.__doc_ …
4
votes
Part 2 of blackjack game
Indentation
You should indent 4 spaces. Here's the PEP 8 guidelines on this.
Equality
Instead of
while (sum(player) <= 21 and stay == False and play_again == True):
do this
while(sum(player) …
2
votes
List the number of times a word occurs in a website article or PDF
Have a look:
name=input("Name: ") # WRONG
name = input("Name: ") # CORRECT
This is a convention outlined in PEP 8, the python convention guide. …
0
votes
This program asks users to rank an item and validates the rank
Your getRank function could use a little flexibility. If the user inputs low, their input is rejected as incorrect. To solve this you can take the first character of the string passed. Since you index …
5
votes
Substring match within a text for given keywords
Unnecessary parentheses
Switch the following:
return(...) -> return ...
if(...) -> if ...
You switch between the two, probably due to coming from another language. Just try to be consistent and don't …
0
votes
Find two numbers that equal to target value
You can accomplish this with itertools.combinations. A lot of the pythonic code you will see is just clever use of built-in functions and libraries. Getting familiar with these will greatly speed up y …
2
votes
2
answers
94
views
Store interface
I've written classes Store, Cart, User that manages methods that allow the user to add/remove products from a shopping cart, as well as being able to query different descriptions about the item (id, p …
3
votes
Accepted
A countdown numbers game solver
Use of global: It's not recommended to use global variables in python, or any language. This StackOverflow answer provides more insight. …
1
vote
Cryptogram Puzzle
You've essentially built a glorified Caesar Cipher. Not all of the changes I suggest below are included in the final version of the reviewed code, but they should be considered. Here they are:
Comme …
1
vote
A small python identifier generator for users
General Changes
Move any input code to the bottom of the file, inside a main guard.
Avoid using global variables, instead pass them as parameters.
Variable names should be in lowercase or snake_case. …
1
vote
CLI Menu library
Naming: Python variables and parameters should be in snake_case, not camelCase.
len as condition: You shouldn't use if len(self.title):, instead you should check if it doesn't exist, if not self.title, …
1
vote
Making a File explorer with Python tkinter
Reserved Names
type is a reserved name (function) in python, so you should rename it to something like file_type, or along those lines.
While we're talking about variables names, what are these? …
2
votes
Advent of Code 2022 - Day 3
Disclaimer: These type hits are written using Python 3.11, so you might need to update your python to run with type hints. If that's not possible, simply remove them. … Reading lines from files
Instead of checking yourself if you've reached the end of the file, let python do it for you
def read_inputs_from_file(filepath: str) -> list[str]:
with open(filepath, 'r') …
2
votes
Accepted
Create 1% Sample Using Multiprocessing in Python
Disclaimer: I have never worked with multiprocessing, so I can't comment on that implementation.
Handling Files
I noticed at the top of the file you open a file, but never close it. (For the argum …
7
votes
Accepted
Find unique characters and count non unique characters
A simple and pythonic way to accomplish this is using collections.Counter. It's an easy way to count elements in an iterable. Have a look:
from collections import Counter
def unique_letters(string: …