Skip to main content
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
Results tagged with
Search options not deleted user 177928

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.

3 votes
Accepted

Simple Poker Counter

Docstrings You should always use triple double quotes for docstrings. ''' should be replaced with """ Comments Don't fill your code with comments. The actual code is harder to read. Comments shou …
Sriv's user avatar
  • 2,760
17 votes

Finding an element without pair in a list O(n**2)

You can use collections.Counter to solve this problem with a time complexity of O(N) and a space complexity of also O(N). from collections import Counter my_array = [1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, …
Sriv's user avatar
  • 2,760
1 vote

Counting without zeroes

""" Prints the next lexicographically smallest string infinitely: a, b, ..., z, aa, ab, ..., zz, aaa, ..., zzz, ... """ # Entering a list as default parameter should be avoided in python
Sriv's user avatar
  • 2,760
4 votes
2 answers
477 views

Run length encoder decoder

The code works not only as a normal run length encoder and decoder, but it also works for values like 3ABC (Prints ABCABCABC), but the same doesn't happen for encoding class DecodeError(BaseException …
Sriv's user avatar
  • 2,760
3 votes
Accepted

Trellis Generator

Edit: If python 3.x is allowed: h, w = map(int, input("Enter EVEN 'height width' of trellis: ").split()) print('--' * (w+1), *(("|" + "/\\" * w + "|") + '\n' + ("|" + "\\/" * w + "|") for _ in range(h) …
Sriv's user avatar
  • 2,760
2 votes
Accepted

Simple python string to list parser

The bool of empty values are False in python. …
Sriv's user avatar
  • 2,760
6 votes

Divide by two a number in base -2

Also, calculate_number should be from_base_minus_two Use type hints Instead of x == 0 python allows you to use use not x. Similarly, x != 0 can be replaced with x. …
Sriv's user avatar
  • 2,760
5 votes
1 answer
68 views

Convert string to fishy and fishy to string

Inspired by this question. Here's the code: class FishyError(Exception): __module__ = Exception.__module__ def string_to_fishy(string: str) -> str: """ Converts a string to fishy code …
Sriv's user avatar
  • 2,760
3 votes
1 answer
150 views

Video Game using tkinter

I created this game inspired by this problem: https://www.codechef.com/ZCOPRAC/problems/ZCO14001 The problem needs you create a machine that can lift boxes and drop them in a new column. Then, when …
Sriv's user avatar
  • 2,760
2 votes
1 answer
156 views

Interactive Tower of Hanoi

I created this program some time ago. It shows you how to solve tower of hanoi for n disks, step by step. Here's the code: from os import system from colorama import Fore, Style clear = lambda: sys …
Sriv's user avatar
  • 2,760
2 votes
1 answer
212 views

Collatz sequence using Python 3.x

I created this program originally for Project Euler 14. Here's the code: from sys import setrecursionlimit setrecursionlimit(10 ** 9) def memo(f): f.cache = {} def _f(*args): if ar …
Sriv's user avatar
  • 2,760
3 votes
Accepted

I have a working Dijkstra algorithm code for solving mazes but I am looking for more perform...

I believe the code is slow because you are using normal Dijkstra, which takes O(V^2) where V is the number of vertices (Here, V would be N*M). This is because you are searching for the minimum by ite …
Sriv's user avatar
  • 2,760
6 votes
Accepted

Small FizzBuzz program

When order of RULES matter, prefer a list of tuples instead of a dict as a dict's order might change depending of the version. You can iterate through the tuple with for divider, value in RULES If al …
Sriv's user avatar
  • 2,760
6 votes
1 answer
2k views

Project Euler problem 26 in Python

Link: https://projecteuler.net/problem=26 I tried to solve it in Python: My approach: For every d, assume you are solving for 1 / d by hand. … Here's my code following the above steps in Python: LIMIT = 1000 # The maximum length maxi = 0 # The 'd' that has maximum length maxi_d = 1 for d in range(1, LIMIT): quotient = [] # Stores the …
Sriv's user avatar
  • 2,760
2 votes

Tic Tac Toe Game in Python 3

Parentheses for if statements should be avoided if (self.draw[0] == self.draw[1] and self.draw[1] == self.draw[2]) : should be replaced with if self.draw[0] == self.draw[1] and self.draw[1] == self.draw[2]: In python
Sriv's user avatar
  • 2,760

15 30 50 per page