Skip to main content

Questions tagged [python]

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.

Filter by
Sorted by
Tagged with
-3 votes
1 answer
65 views

3 tables in SQL [closed]

Lets say i have 3 tables: users, posts and comments. ...
busuu's user avatar
  • 97
-3 votes
1 answer
6k views

Python class for chess pieces [closed]

Please review my current try of creating a class for chess pieces. I not only want to be able to play a game of chess with this but also solve chess puzzles, thats why I want a flexible board size and ...
Tweakimp's user avatar
  • 769
-3 votes
1 answer
7k views

Memory error in python [closed]

I am writing a code which returns something like 1^k + 2^k + 3^k......n-1 where k be any number.Below is my code.I am getting a memory error.How do I optimise it. Sample test case for wrong error: 1 ...
Leo B Jacob's user avatar
-3 votes
1 answer
964 views

Caesar cipher using the word length as key [closed]

Here is a code I'm working on that alters a individual letters.Each letter is pumped up x amount of letters. This alteration is dependent on the length of the word. So for instance "hi" becomes "jk", ...
Collin Stump's user avatar
-3 votes
1 answer
1k views

how can I avoid use global variable in this code? [closed]

...
roger's user avatar
  • 115
-3 votes
0 answers
28 views

How to use variables and declare values in classes [closed]

I am new at writing production code, and I want inspiration on how to use variables when I write classes. I use Python here but this can be generilzed to other languages. What is good programming ...
economist101's user avatar
-3 votes
1 answer
67 views

Generating a Latin Square (Modified Algorithm) [closed]

Sifting is used to create a Latin Square of distinct symbols. The sifting is implemented by swaps on an array. The symbols might be strings or integer, but they are required to be distinct. Notably, ...
Akash Patel's user avatar
-3 votes
1 answer
50 views

Whats a more object oriented way to execute a python script [closed]

The following code cd's into the scrape folder, and enters the command "scrapy crawl yellow". It works well, however i want to make this more object oriented looking, utilizing something like ...
randal's user avatar
  • 101
-3 votes
1 answer
321 views

Challenge Atlas Game in Python [closed]

Here is my code: https://gist.github.com/Salil03/5fb4d512b97324c89e2580f94725a7fd The instructions are printed out from the python file. They are given here for convienience You start by ...
Agile_Eagle's user avatar
-3 votes
1 answer
62 views

Extremely simple python password generator [closed]

I tried to make a password generator and at first it works as intended, generating a password with lowercase, uppercase and special characters but I can only generate passwords of up to 19 characters ...
gqToru's user avatar
  • 1
-3 votes
3 answers
86 views

Opinion on Python exceptions? [closed]

Just looking for opinions on which is the best way to use exceptions? Should the exception handling go inside the function or should it go outside the function when you actually call the function. ...
alicia johnson's user avatar
-3 votes
1 answer
65 views

Reducing function calls with Map [closed]

Currently I am working on reducing function calls in my tool. My function is called add_field_and_calc ...
JuniorPythonNewbie's user avatar
-3 votes
1 answer
69 views

how to simplify conditional code in python [closed]

I am a student I am new to python, This is my first code, any one help me to simplify this code. ...
Mohamed Afzil's user avatar
-4 votes
1 answer
257 views

Python: Computing \$e\$ [closed]

I was trying to solve a problem which stated: Calculate the first 10 digit prime found in consecutive digits of e. I was able to solve the problem but I did it by using some 10k digits of e ...
Aaryan Dewan's user avatar
-4 votes
2 answers
213 views

Reading a product from JSON that may or may not have a size [closed]

How to do optimization and provide less of code here: ...
user2734570's user avatar
-4 votes
1 answer
8k views

Python PID simulator controller output [closed]

I have written a piece of code (in Py3) that graphs out the controller value of PID controller. This is so that by changing the various sub controllers (P/I/D) I can visualise how the graph changes. I'...
3kstc's user avatar
  • 125
-4 votes
2 answers
80 views

What are other ways of finding Max and Min in python, other from my method? [closed]

How my method works is by sorting the list of numbers from least to greatest, finds the length of the list, then pick the first and last index integers. In the python world is this efficient or is ...
Tam-Fils Salomon's user avatar
-4 votes
2 answers
232 views

How to make this snippet DRY (Don't Repeat Yourself) [closed]

I know it's not that bad, but I can't help but wonder if there is a way to make this DRY-er. ...
Matias K's user avatar
  • 213
-4 votes
1 answer
67 views

Adding numbers using subtraction instead [closed]

This is subconcious coding. This is not new by any means at all! I am only keeping the question because I can't delete it. I've just realized that subtracting negative numbers from zero gives the ...
Vikram Durai's user avatar
-4 votes
1 answer
900 views

What are the time and space complexity of this algorithm? [closed]

What is the time and space complexity of this algorithm and can it be improved (how)? It generates random 4 digit even number and the adjacent 2 digits must be different. ...
user140586's user avatar
-4 votes
1 answer
3k views

How to find adjacent elements in multidimensional list in Python? [closed]

Here I have a multidimensional list in python. Suppose I take an input, how do I find the number of adjacent elements of that input which are alphabets other than itself? If there are multiple indices ...
SVM's user avatar
  • 1
-4 votes
1 answer
63 views

What is the time complexity problem I need to manage on a Hackerank "Ransom Note" - my code runs perfectly [closed]

I am trying to solve the "Ransom Note" problem on hackerank. Why isn't my code getting submitted? What can I do differently? is my total time complexity, in this case, it is O(n^2)? ...
Kar19's user avatar
  • 159
-4 votes
1 answer
84 views

Generate the 100th "look and say" number

This program finds the 100th member of the "look and say" sequence: 1 11 (one 1) 21 (two 1's) 1211 (one 2 and one 1) 111221 (one 1, one 2, two 1's) 312211 etc. ...
Kazz's user avatar
  • 186
-4 votes
1 answer
90 views

Santa Claus, its dwarf and its reindeer

I have the following class. The aim is to have a few methods that deal with the type of the gift, the dwarf who is packing the gifts and the time he will take. And finally, the reindeer, which is ...
Andy K's user avatar
  • 612
-4 votes
1 answer
103 views

Rapidly searching the internet with small breaks

Sometimes, I have a lot of things I want to ask the Internet, so I decided to make my searches go faster with some automation... But I think this could be programmed better, even though I think it's ...
Malady's user avatar
  • 99
-4 votes
1 answer
91 views

Finding the sublist with best utility function among all list's permutations [closed]

I try to find the the better solution in terms of time complexity. Among the list of elements I need to find the sublist with maximum value of given utility function. Each element has it's own type. ...
Daniel Chepenko's user avatar
-4 votes
1 answer
292 views

Calculate product restocks [closed]

Read the current inventory from a file. Either adjust inventory based on orders or generate a purchase of new inventory. When a product goes below a certain point, it will be asked to calculate it ...
Tony's user avatar
  • 1
-4 votes
1 answer
108 views

Style guide on writing long Python code lines [closed]

When building a working example of a class, I ended up with the following statements which is violating the 80 character rule of PEP8. The code was inside a method inside a class. Code excerpt is ...
holroy's user avatar
  • 11.5k
-4 votes
1 answer
33 views

Find characters from same homeworld as Chewbacca [closed]

The problem is Find the names of all characters which are from the same homeworld as Chewbacca My code is ...
su sahin's user avatar
-4 votes
2 answers
120 views

Clean up if else statement [closed]

Background I have a simple logic where i get total_kits. I usually make some function call to get the value for this variable. Then if ...
Dinero's user avatar
  • 387
-4 votes
1 answer
339 views

How can I reduce the TIme Complexity. of the python program

I have 7000 CSV files that I want to do operation on. but the problem is that it takes to much time like it takes 13 seconds to process these files. What I need to know is which operation take more ...
Hazrat ali's user avatar
-4 votes
1 answer
5k views

What is wrong with my 'except' code here? [closed]

I am learning python and am working through some try and except codes. What is wrong here? The code aims to convert the input ...
william3031's user avatar
-4 votes
1 answer
108 views

Parsing million words of list in python regular expression is slow [closed]

I have been working on a project in python which takes content from web links and find some important words from content of that page. I used regular expression to do so. But it takes huge time to get ...
Neeraj Sonaniya's user avatar
-4 votes
1 answer
53 views

Incremental Count and it's position in Python [closed]

I have a requirement to get incremental counts. I am new to Python so please help me. I have tried below: ...
gopal's user avatar
  • 1
-4 votes
1 answer
579 views

Python - Performance of this code very slow [closed]

This is an excerpt of my html code ...
Srinivas's user avatar
  • 103
-4 votes
1 answer
52 views

Test case where code fails [closed]

I've been trying to find the minimum steps it takes for a number to be reduced to 1 given the three following steps: Divide by 2 Increment by 1 Decrease by 1 My code is as follows: ...
amateurprogrammer's user avatar
-4 votes
1 answer
82 views

How could I write that code more clearly? [closed]

I mean, that code should be written more clearly. Can you help me, have you yet one idea ? I Need to assign the value list_new to variable depending on the list ...
get_function's user avatar
-4 votes
1 answer
107 views

basic two-player tic tac toe game [closed]

Here is my code: ...
fartgeek's user avatar
  • 257
-4 votes
1 answer
2k views

Finding The Largest Digit in a Number using a Recursive Function in Python [closed]

I tried it using the code given below. ...
Aritra Pal's user avatar
-4 votes
1 answer
55 views

Is it good practice to give a value to a variable, then change its value immediately after? [closed]

Is it good practice to give a value to a variable, then change its value immediately after, like that for example? ...
G. Langlois's user avatar
-4 votes
1 answer
65 views

Geting maximum prime factor for a given number [closed]

I'm trying to solve a problem from Project Euler: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? and here is my attempt: ...
Krushe's user avatar
  • 1
-4 votes
1 answer
1k views

Fetch items of a nested list using lambda expression [closed]

Is it possible to fetch using a lambda expression. Structure of nested list: An overview [sent1, sent2, ..., sentn] for ...
Logan's user avatar
  • 291
-4 votes
1 answer
3k views

Removal of Duplicate Urls in list [closed]

Here is a piece of code for acquiring URLS ...
Rembrandt's user avatar
-4 votes
1 answer
88 views

Well Functioning Calculator in python [closed]

...
blackk_iverson's user avatar
-4 votes
1 answer
91 views

What does %s mean in a python strings? [closed]

I'm not sure what %s means in Python strings. I came across this line of code somewhere a while ago: ...
fast_and_curious's user avatar
-4 votes
1 answer
165 views

Python Code Classes Tkinter [closed]

I am learning to write my codes accordingly with functions and classes. My original code can create a graphic interface that interacts with different functions. As I said before, I am trying to write ...
Martin Bouhier's user avatar
-5 votes
1 answer
248 views

Return a sum unless one of the values is illegal

Is there a way to make my code more concise? Given 3 int values, a b c, return their sum. ...
noob81's user avatar
  • 163
-5 votes
1 answer
272 views

Arithmetic quiz for student groups

...
Daniel Fisaha's user avatar
-5 votes
1 answer
124 views

How good is this cipher? (Python)

I made a cipher on python and I want to know how good it is, I calculated there are about 10^1025 possibilities for the key, is that any good? I can easily make it bigger. I mainly focused on the '...
Tudor Popescu's user avatar
-5 votes
2 answers
1k views

TV guide program and client server with sockets [closed]

I am fairly new to Python coding, although I have been coding on and off for 30ish years. I am sure I am writing Python with too much influence from the other languages, such as REXX, VB, and some ...
user2980402's user avatar