I have a binary number, how can I group the same digits in pairs and split the number on single zero? For example: Answer You could use an iter of the string to compare the current character to the next one. If they are the same, add them to the current block; if they are different, the first one must
Tag: python-3.x
Get the number of specific dictionary values being stored in a 2-dimensional list in Python
I have a dictionary that contains fruits as keys and a 2-dimensional list including the line number and the timestamp, in which the fruit name occurs in the transcript file, as values. The 2-dimensional list is needed because the fruits appear several times in the file and I need to consider each single occurrence. The dictionary looks like this: Now,
How to Catch Exception in for loop and return exception only after loop is done?
Hi I have a function that parses the first 60 lines in a file and is supposed to alert a user if there are lines that are entirely whitespace. However these can occur anywhere in those 60 lines so I want the script to parse the entire 60 lines mainly because I need data from a couple of the lines
Python program works only from pycharm, not somewhere else
The script works fine when I run it in pycharm, but if I run it from somewhere else it just doesn’t work. When I run it via cmd it gives me this error: The Python version in both the terminal and in pycharm are the same. There is a virtual environment set up in pycharm. Answer Try pip installing the
Write a python code to merge two list with the following condition [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question If two list is having same number, then the final list should not have the number Answer Check this code:
Load and Save Dictionary and Class Instances Python Script
Writing a python script that prompts the user by asking if they are are new or an existing user. If new, they will create a username, password, age. A User class instance should be created with that information along with adding the new username and password to the security dictionary. Once registered, or an existing user, it will be prompted
Don’t understand why my function can’t be called
I try to make a little text based rpg with python. And the first thing that I want to make is an input to equip armor or weapons. So here is the problem: my function find_armor is not calling whatever I enter. If my first word is “equip” the output is always: your armor: 0 0 Answer In a function,
Collatz’s hypothesis testing in Python
I am trying to build a small program to test the collatz’s hypothesis. So far, I have the following: But when I run it, it’s going into an endless loop of 0.0s. Not really getting where the problem is. Answer As Nearoo mentioned, c0 % 2 is the same as c0 % 2 != 0 because 1 (when c0 is
Group by 2 columns with calculation of quantile of 3rd numerical column
I have a df below as: I have code below that calculates the % of each mealtype for each day How can I tweak this code to give me the quantiles – p50 and p90 of the oz column, but grouped by mealtype day and mealtype as well? Thanks! Answer You can try this or output
How to stop a GUI from being automatically resized?
I wrote a calculator app by using Tkinter. The problem is when I click numbers or operators etc, the whole GUI resized automatically. Actually, I think the width of the label must fix in some way. I tried to use a frame as the parent for the label but it didn’t work. Should I use a different layout manager? Here