Questions tagged [python]
This challenge is related to the Python language. Note that challenges that require the answers to be in a specific language are generally discouraged.
143 questions
0
votes
1
answer
80
views
Golf a number bigger than all other answers [duplicate]
You have to code in python, and the number generated by your code must be bigger than all other current submissions. You need to make your code as small as possible, it has to terminate but you can ...
0
votes
1
answer
326
views
How can I shorten this Python code from 214 bytes to under 200 bytes? [closed]
I have the following Python code, which is 214 bytes long:
...
1
vote
0
answers
90
views
Write a piece of Quine code that can be excuted by both C and Python [duplicate]
Write a piece of code that is compatible with both C and Python compilers/interpreters, which can output its own source code.
Quine is quite easy, but how about this double language version?
Hint:
To ...
6
votes
4
answers
637
views
Is there a shortest code to format string
Code Golf Challenge
Given a string of 10 characters:
'abcdefghij'
I want to format it in this pattern and print it in the console in a minimum number of characters:
...
8
votes
1
answer
562
views
Self-referencing tuple in python
Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only.
Answers meeting this extra ...
-3
votes
1
answer
588
views
What is the ABSOLUTE shortest way to write this code?
So I got kinda bored and was wondering if it was possible to make this code shorter without modifying anything except a file named coin.py...
...
6
votes
2
answers
450
views
Shortening this Code to process nested tuple even further without the use of max()
I have the code:
...
9
votes
2
answers
691
views
Inverting string-based binary number in one line in Python
I want to read two strings on separate lines, each string the same length and containing only 0's and 1's, and determine if the first is the one's complement of the second. How succinctly can this be ...
14
votes
16
answers
3k
views
Speed up, slowpoke!
In this king-of-the-hill challenge, you will program a bot, consisting of a python function of the form
def BOTNAME(info, me, round):
pass # ... main body
...
8
votes
2
answers
354
views
How to shorten Python code involving the sum of reciprocals?
I have a coding problem that goes like this:
Given a positive integer \$N\$, return a list of all possible pairs of positive integers \$(x,y)\$ such that $$\frac1x+\frac1y=\frac1N$$
I already solved ...
9
votes
2
answers
982
views
Can I shorten this Python code for simulating a car driving around
I am trying to write a solution to the following problem using as few characters as possible (to meme my friend and introduce him to golfing). Can any improvements be done to my code?
So the problem ...
9
votes
4
answers
3k
views
How to shorten the python code?
I'm writing a program that takes a number from input (call it x), loops from 0 to (x - 1) (let's call our iterator y) and prints \$y^x+x\$ for each y.
After the loop, it then prints "SUM: N" ...
6
votes
2
answers
474
views
Pushing the limits to make a piece of code solving the K-Goodness String problem shorter
I am trying to push my limits of making a python code as short as possible.
I left the readability part way behind.
I was attempting the K-Goodness String problem from Round A of Google Kick Start ...
4
votes
2
answers
1k
views
Write an infinitely nested generator comprehension
The goal is to create a generator generator [...] generator generator comprehension.
The generator must be created via generator comprehension.
The following expression must be valid for any number ...
9
votes
2
answers
4k
views
How to ignore first user input in Python 3
I have 2 inputs: 1 single number and some numbers separated by whitespace:
1
1 2 3 4 5
I want to loop over the second input, and I don't need the first input. I ...
8
votes
6
answers
798
views
KotH - Floating Point Prisoners Dilemma
Background
So, nowadays the popular Prisoner's Dilemma variant is the Prisoner's Trilemma, where there are three options. I can easily see that being increased, so I figured
Why settle for three ...
6
votes
6
answers
1k
views
Let's play Judgement!
In this king-of-the-hill challenge, you will be making a python 3 bot to play the card game judgement!
Sandbox
Rules
Judgement is a hand based game similar to games like rummy. In each round,
7 cards ...
8
votes
1
answer
437
views
I'm Jelly of Python (Robbers)
What does "jelly" mean in the title?. Cop's thread
Robbers, you are to choose an uncracked Cop answer, and attempt to find a Jelly program which is:
shorter than the Cop's answer
solves the ...
16
votes
17
answers
1k
views
Liars and Guessers
Github
You have probably played, and may even have written a program to play, a simple number guessing game. If so, this probably looks familiar:
...
-7
votes
1
answer
214
views
No. Of Factors Does the Number Have [duplicate]
Create a function which takes in a input integer and then returns the number of factors it has, like if you pass 25 then it will return ...
3
votes
2
answers
662
views
Remove duplicates from list and order it by count? (python 3)
How do I remove all duplicates from list and order it based on count?
...
1
vote
2
answers
849
views
Shortest Python 3 for sum of arithmetic progression
Input: from STDIN number of vertices in Graph \$2 \leq N \leq 100\$.
Rules: [Code size] = max ([code length without spaces, tabs and newlines], [total code length divided by 4])
Math formulation: In ...
16
votes
8
answers
1k
views
Omit needless spaces for me
A great Python golfing tip is to omit needless spaces. But if you are like me, you don't always have the time to search for which spaces to remove. If only there was a way to speed up the process...
...
4
votes
2
answers
3k
views
Shortest Solution in Python 3 for Caught Speeding - CodingBat
I am trying to find the shortest code in python 3, to solve this problem:
You are driving a little too fast, and a police officer stops you.
Write code to take two integer inputs, first one ...
11
votes
3
answers
854
views
Decode ascii and reversed words sentence
In a challenge of CodingGame, there is a challenge that ask you to decode a string composed by reversed words ('Hello world' > 'olleH dlrow') then each characters converted into ascii value separeted ...