Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-2
votes
0answers
76 views

Looking for teammates [on hold]

everyone is looking for a teammate. There are N contestants (numbered 1 through N) who want to participate let's denote the skill level of the i-th contestant by \$S_i\$. These people want to pair up ...
-3
votes
0answers
40 views

Least possible sum by using only 2 operations [on hold]

If a number is given and an other number say s . Condition is u can only perform 2 operations: either u can sum the digits of number or u can add s to the number. So what will be the least possible ...
55
votes
37answers
9k views

Robot Roulette: High stakes robot gambling

Final Standings +----------------------------------+---------+---------+---------+----------------------------+ | Name | Score | WinRate | TieRate | Elimination ...
3
votes
4answers
402 views

Russian BS - Submissions accepted until October 13th

The ChatRoom is here I love playing the card game BS, but sometimes, it just doesn't have enough oomph for my short attention span. Instead, let's play some Russian BS. Rules Here is a quick guide ...
8
votes
4answers
281 views

Get the lowest possible pylint score within 128 bytes of python

pylint has no lower bound on the scores it will give your code. It uses the following metric to score code, with the maximum score being 10: ...
9
votes
3answers
471 views

Partially-Observable Connect-4

The Game You will be playing an (almost) standard game of Connect-4. Unfortunately, it is a correspondence game and someone has placed black tape on every second row starting from the bottom, so that ...
1
vote
1answer
351 views

Dictionary Code Golf [closed]

New to code golf and enjoying it. I have a problem that I cannot figure out and am curious if others can solve it. Start with two dictionaries, y and ...
30
votes
3answers
4k views

Primality testing formula

Your goal is to determine whether a given number n is prime in the fewest bytes. But, your code must be a single Python 2 expression on numbers consisting of only ...
-3
votes
1answer
114 views

make this bubble sort python code shorter than this? [closed]

i don't know if it can be made shorter than this ...
7
votes
2answers
284 views

Python: shortest way to interleave items from two lists

I'm trying to get the shortest way (character possible) to obtain List 3. List 1 and List 2 are already given to me as arguments and are the same length. ...
12
votes
9answers
792 views

White Elephant Exchange

It's Christmas in July, so what better way to celebrate than a virtual white elephant gift exchange! For this King of the Hill challenge, you must create a bot that plays in a White Elephant exchange ...
4
votes
5answers
966 views

Reducing a Python Script [closed]

Does anyone have any suggestions as to how I could shorten this program? ...
6
votes
4answers
634 views

Write a Program for winning sevens game

Build a function in python that can win a Sevens game provided that there are only 2 players Here are the instructions from Wikipedia: All cards are dealt to the players, even if as a result some ...
10
votes
2answers
428 views

Camel Up Cup: An AI board game tournament

Camel Up Cup 2k18 In this challenge, we will be playing the semi-popular board game Camel Up. Camel Up! is a board game that has players betting on camels to win rounds, win the game or lose the ...
-3
votes
2answers
185 views

Zero sum in python 2.7 [closed]

Write a function in Python 2.7 that takes a list of integers as an argument. It should return True or False depending on whether there are any 2 integers in the argument list that sum to zero. [4,-4,9,...
34
votes
23answers
3k views

Noisy Iterated Prisoner's Dilemma

In this challenge, you will play the noisy iterated prisoner's dilemma. The Prisoner's dilemma is a scenario in game theory where there are two players, each with two options: cooperate, or defect. ...
29
votes
3answers
503 views

Build a golfing language with me

A lot of PPCG users helped with the creation of this challenge, both in chat and the Sandbox, specifically Martin Ender, AdmBorkBork, Emigna and user202729 Our community has found it necessary to ...
11
votes
2answers
218 views

Tips for golfing with numpy, scipy, or pylab

There's already a comprehensive list of tips for python here, so what I'm asking for are tips that specifically apply to using the numpy, ...
-4
votes
1answer
241 views

Number of leap years between two given years (inclusive) [closed]

Is there a better way to calculate the number of leap years between two given years? I want to make my code shorter (in Python). Do you have any suggestions? Here is my solution: ...
13
votes
1answer
459 views

Let's write a Minifier

Background Minifiers are used, commonly, when serving JavaScript to your Web Browser. It is commonly used to reduce the number of bytes that have to be sent. Saving bandwidth is useful for obvious ...
3
votes
0answers
98 views

Print a flag in as little lines as possible! [duplicate]

Just for fun, I wanted to see how little lines I could solve this problem in, using python. I managed to condense my code into 9 lines. ...
32
votes
34answers
4k views

First-price sealed-bid auction

Final Result The competition is over. Congratulations to hard_coded! Some interesting facts: In 31600 out of 40920 auctions (77.2%), the winner of the first ...
12
votes
2answers
2k views

How can I shorten this python code?

Here is the code which I want to shorten. ...
57
votes
27answers
7k views

Honest Rock, Paper, Scissors

Many people consider RPS to be a game of chance. If both players play unpredictably, the best strategy is to play randomly. However, let's introduce a bit of predictability to it. Each bot will have ...
68
votes
11answers
12k views

How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

This is a tips question for golfing in Python concerning the Evil Numbers question on Anarchy Golf. An number is evil if its binary expansion has an even number of 1's. The challenge is to print the ...
6
votes
3answers
272 views

Slice, Slice, Maybe

Everyone loves slicing in python, as in array[5] to access the fifth element or array[:5] to access the zero through fourth ...
13
votes
7answers
966 views

Chopsticks mutated with points KoTH

Basic rules (different from mine) Story It is the year 4579, humans now have 2 hands with 1001 fingers each. Chopsticks has become based off of points. And @Dennis has more rep then @Martin... Hand ...
13
votes
1answer
981 views

Most common elements of a list in Python

This is a tips question for golfing in Python, which is on topic for main. I'm looking for the shortest way to get all of the most common elements of a list in Python, in the shortest way possible. ...
21
votes
1answer
342 views

Golfing Python string literals

Background Python 3 has many types of string literals. For example, the string this 'is' an exa\\m/ple can be represented as: ...
8
votes
6answers
1k views

Dungeon of botdom

– of crisis and martyrdom (that's the subtitle because subtitles are cool) In this king-of-the-hill challenge in python (yup; you need go no farther to know you may not submit in java), you need to ...
12
votes
19answers
2k views

KOTH - Loaded RPS

Contest permanently opened - Updated August 10th Even though on June 5th I declared a winner (who will be kept as the best answer) I'll be rnning new bots and updating the results. June 5th Results ...
15
votes
23answers
2k views

Prisoner's Dilemma v.3 - Petri Dilemma

A mad scientist has just created a new species of bacterium! He has decided to name it Noblus Gentlemanus, after observing its behaviour. However, his bacteria have ran out of food, and have ...
2
votes
0answers
48 views

Skip or delete lines between two keywords in a file using python [closed]

The problem is I need to skip or delete all the lines between the two keywords in a file and the keyword pair will appear many times in the file.The file looks something like this ...
20
votes
2answers
754 views

Are these lists equal?

As you may very well know python has lists. As you might not know these lists can contain themselves. a = [] a.append(a) Python 2 Python 3 These are cool and ...
11
votes
1answer
1k views

Shortest python A + B program with input and output

Some of you may say that I am wasting my time, but this task does not give me peace for more than 500 days. It is required to write a program in Python 3.x that takes two numbers as input and displays ...
7
votes
4answers
440 views

How can I golf this code to count all perfect squares below 100?

I'm trying to strip down my python code to be as few lines as possible. The task: count how many square numbers are below 100. Here's my code so far: ...
31
votes
5answers
2k views

Python workarounds for assignment in lambda

This is a tips question for golfing in Python. In Python golfing, it's common for a submission to be a function defined as a lambda. For example, ...
10
votes
4answers
372 views

Abstract Syntax Tree Golfing: FizzBuzz, Python

Summary Implement FizzBuzz in Python, with the fewest possible tokens. Challenge Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” ...
13
votes
5answers
1k views

Add comments to a Python script and make it a bilingual Python/C++ “program”

Given the following Python 3 script: def greet(): print("Hello, world!") greet() Prepend some lines to this text file so that it can be both executed as a ...
34
votes
4answers
2k views

FOIL Python's strong typing!

Your task is to write some code in Python 2 or 3 such that this expression: (a+b)(c+d) == a*c + b*c + a*d + b*d will evaluate to ...
-2
votes
1answer
269 views

Import this into your own language [duplicate]

The Zen of Python must surely be one of the most beautiful Easter eggs in any language. (It is created by writing import this) So why not create a version for your ...
10
votes
1answer
587 views

How to find the item in a list whose f(item) is the smallest?

I have a list, l and a function f. f is not strictly increasing or decreasing. How can I ...
7
votes
3answers
442 views

How can I shorten this python code analyzing a 3d grid?

My Python 3 function golf(...) should take a list of lists of lists of strings representing a solid cube and return whether there are any places in which two equal ...
4
votes
1answer
678 views

Need help golfing Python 3 code to calculate volume & surface of spheroids in <150 bytes

I want to write a function golf(C, A) that takes the height (C = 2*c) and the width (A = 2*a)...
13
votes
4answers
536 views

Strategies for representing a given large integer using arithmetic expression

I have a specific number in mind, but it's part of a challenge I'm doing, and I don't want people to do (all) the work for me. Here is a number which has the same digits, but shuffled: ...
3
votes
0answers
306 views

Most creative/diabolical/entertaining way to find Python version? [closed]

There are important differences between Python 2 and 3, so it's often useful to know which version of the interpreter is running your code. The straightforward method is something like this: ...
3
votes
2answers
322 views

Shortening str.replace() [duplicate]

In Python it is often necessary to use str.replace(a,b), however .replace is rather long and feels unnecessary. So is there a ...
5
votes
4answers
421 views

Returning the range of a number as a palindrome

I like to do programming challenges in my free time to teach myself and keep fresh, this one I can't seem to optimize though and it's driving me insane. The goal is essentially, "Given a number, ...
-2
votes
1answer
1k views

Python Golfing Suggestions [closed]

I have read: Tips for golfing in Python I would like to golf this code further. Any more tips? ...
4
votes
5answers
401 views

Python Code Reviewer

Task Your mission is to create a program that reviews Python code. The solution can be written in any language! It must take input that contains python code. The program must add ...