All Questions

Tagged with
Filter by
Sorted by
Tagged with
-2 votes
0 answers
20 views

suggestions on password generator [closed]

I wrote a little password generator code trying it out just to see if i could figure it out i am writing it to a file but it comes out in a progressive fashion im trying to get codes of 8 not i, 2, 3, ...
4 votes
4 answers
414 views

A function that uses a regex to parse date and time and returns a datetime object

The code works, but I think can be simplified, I don't know which specific steps, but my version seems to me quite complicated I build a function that takes a specific string format and returns a <...
6 votes
3 answers
157 views

Reversing words of a string without using inbuilt functions

I was wondering if I could reverse a string without using collections and in-built functions of string, Please do add your thoughts on the approach and if possible do share your way of the solution. <...
  • 61
3 votes
1 answer
66 views

SImple Inverted Index

This is a simple inverted index I made. The goal is to: Read set of text files from a directory, docs Tokenize them Normalize the tokens by removing punctuation ...
0 votes
1 answer
79 views

Short Text Pre-processing

For educational purpose I am preprocessing multiple short texts containing the description of the symptoms of cars fault. The text is written by humans and is rich in misspelling, capital letters and ...
1 vote
3 answers
129 views

Convert camelCase function name to snake_case

I have the following code: ...
  • 11
2 votes
1 answer
37 views

Optimising function to strip honorifics from names

Problem I have a list of around ~1000 honorifics, see below for a sample. Given an input string of a name, for example ...
  • 233
3 votes
2 answers
211 views

Add two numbers represented as digit strings

This algorithm adds two numbers digit by digit using their string representations. I am wondering what the time and space complexities of the following algorithm are. In particular, I am wondering ...
0 votes
2 answers
65 views

Reversing a Python string using [::-1] [closed]

I'm learning how to reverse list and strings. Is there another way of reversing a string other than using [::-1] method? even if the other method is the long route i would much appreciate it ...
1 vote
0 answers
61 views

Application for "Good" and "Bad" word checking

This thread is a continue version of Find match words based on a list of words where I now have added Good word dictionary. What I am trying achieve here is that I want to check if a user has a given ...
2 votes
1 answer
109 views

Improving the speed of one-hot encoding a list of strings

I've recently developed two functions to functions to essentially convert a list of strings that look something like this (these strings are 101 characters long in my case): ...
  • 123
1 vote
1 answer
81 views

Encode text to Baudot (teletype) code

After watching Computerphile videos on WW2 cryptography and radioteletype I decided to code a translator to Baudot code. I wonder if it can be somehow improved? ...
2 votes
1 answer
75 views

Remove duplicates from a Pandas dataframe taking into account lowercase letters and accents

I have the following DataFrame in pandas: code town district suburb 02 Benalmádena Málaga Arroyo de la Miel 03 Alicante Jacarilla Jacarilla, Correntias Bajas (Jacarilla) 04 Cabrera d'Anoia ...
  • 143
3 votes
1 answer
166 views

Applying a cost function to a string based on a pattern string

I have a cost function Cost_Func(pt,STRING) that calculates value in a specific way based on the given pattern string pt and ...
  • 133
3 votes
1 answer
207 views

Longest Palindromic Substring | Python Code Giving TLE

Problem Statement Given a string s , return the longest palindromic substring in s. Constraints ...
1 vote
1 answer
258 views

Adding string to a text file without duplicates

I have a function below, store_in_matchid_file, and it adds certain strings to a .txt file as long as that string doesn't already exist in the file. However that ...
  • 27
2 votes
1 answer
115 views

Text splitter using Regular Expressions in Python

I have been provided a text splitter class that will take a text input and use re.sub to make replacements when matches are found and also splits sentences up and stores them in a list. I had an idea ...
1 vote
2 answers
90 views

Transforming a string by combining same duplicate characters

I'm solving a programming puzzle that requires to transform an input string by replacing pairs of duplicate consecutive characters with an "incremented" character, recursively, e.g. "...
2 votes
1 answer
141 views

Extract regular words from string but retain all other elements and record their type

This snippet processes every regular (\w+) word in a text and reinserts the processed version: ...
  • 1,226
2 votes
1 answer
80 views

follow-up - Checking Nested Bracket Levels in Strings Programming Challenge

A follow-up to this question, this post improves on test case issues. To restate problem parameters, a given string S is considered closed if it: Has a matching ...
  • 2,947
3 votes
1 answer
569 views

Python function to output a string that is justified to the right

I just solved this exercise from Think Python, 2nd edition: Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5. Write a function ...
4 votes
1 answer
482 views

Lingo (word-game) guessing strategy

My friend and I are kind of noobs in Python and are looking for ways to improve. We thought it would be cool if we could get some feedback on the following code. It is for a game named "Lingo&...
1 vote
2 answers
117 views

finding whether two string are anagrams of each other [closed]

...
4 votes
1 answer
415 views

String Manipulation: Given two operations on a character 'A', Copy and Paste, find the minimum number of operations to produce a string of length 'N'

I have a solution to the following question which seems straightforward enough. However, I feel as if I am missing something. The question: Objective: You have given a character ‘A’ which is already ...
15 votes
5 answers
2k views

Comma Code, Project from "Automate the Boring Stuff with Python"

I'm a newbie. I'm at Chapter 4 of Automate the Boring Stuff with Python. Comma Code Say you have a list value like this: ...
6 votes
2 answers
175 views

A string separator that doesn't separate if in quotes

The sep function separates string by the characters of seps, but it escapes the separates ...
  • 185
10 votes
4 answers
3k views

First non-repeating Character, with a single loop in Python

I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop. My thinking is, it would be easy to tell you what ...
  • 203
2 votes
1 answer
74 views

Compare strings to markup commentary in main text

...
  • 435
4 votes
3 answers
86 views

Pythonic way of removing one word entries from compound list

Assume a multi-line file (myInput.txt) with lines comprising one or more words. ...
6 votes
2 answers
403 views

Flatten JSON to string

The code below is a Python module to flatten JSON-like structure (nested dictionaries and lists) to a single string. It also provides partial result in the form of flat list of strings. This ...
20 votes
6 answers
4k views

Password validator

I have made a password verification "program" which takes user input and checks whether the password is valid or not. Based on that, a reply is printed. ...
  • 303
3 votes
2 answers
2k views

Separate an email address into its username and domain name

This is my first ever Python program and I wanted to get everyone's opinions on it. The goal of the program is to separate an email address into its username and domain name. ...
3 votes
2 answers
175 views

Parse sequence of characters detecting formatting categories

I am a beginner coder and SonarLint tells me code is too complex. I tried recursion, iterators, slicing but had not luck making this code any simpler. The code will parse the input string to detect ...
4 votes
2 answers
151 views

Retrieving top-level opening and closing sequences from a Python string

The problem I'm solving is a more complex version of pairing up opening and closing brackets. Instead of matching only on ([{}]), I additionally need to match ...
  • 198
-1 votes
1 answer
342 views

Finding longest word in a sentence

A problem from Coderbyte. Find the longest word in a sentence after removing the punctuations and if two or more words are of same length return the first word Below is my solution: ...
  • 585
6 votes
3 answers
616 views

Generate random string to match the goal string with minimum iteration and control statements

The following is my python code to find the number of iterations needed to generate random string iteratively to match the input string. Here I have repeated a similar kind of for loop in both the ...
  • 71
2 votes
3 answers
185 views

Convert string format python

I want to fix number of digits after '.' in digit represented by string. Is there better solution than mine? My code ...
  • 125
2 votes
1 answer
45 views

Input any time, output timezones that are currently that time

I made a program that will take in a time and a weekday, and return which parts of the world are at times closest to the one specified. Part of the program focuses on extracting a date and country out ...
  • 960
3 votes
1 answer
316 views

strstr implementation with python and sets

Please review my strstr implementation in terms of time/space efficiency and overall readability. I am preparing for a coding assessment coming up as I am looking to pivot my career from Physics to ...
  • 31
-4 votes
1 answer
83 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: ...
5 votes
1 answer
793 views

Capitalizing the first letter of every word in a string (with arbitrary spacing)

I solved the following question You are asked to ensure that the first and last names of people begin with a capital letter in their passports. For example, alison heck should be capitalised ...
22 votes
6 answers
7k views

Add 'ing' or 'ly' suffix to a string

I have been practising Python Practice questions and came across this question: Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the given string ...
4 votes
1 answer
2k views

Finding Pattern Score in Python

I saw this problem in C++ on here and decided to try it in Python, which was much simpler. I've used the same problem blurb as in the link above, so they are consistent. I'm sure my code can be ...
9 votes
1 answer
2k views

LeetCode on Longest Palindromic Substring in Python

This is a programming question from LeetCode: Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is ...
user avatar
7 votes
2 answers
722 views

Number of occurrences of strings in array

This is a Hackerrank problem (https://www.hackerrank.com/challenges/sparse-arrays/problem). We're given an array of strings and an array of queries, and have to return an array of the number of ...
6 votes
2 answers
3k views

Python - use a list of names to find exact match in pandas column containing emails

I have an Excel file containing a free-form text column (that sometimes is structured like an email), where I need to find all first and last names and add an extra columns saying TRUE/FALSE to these ...
2 votes
2 answers
284 views

Exercism: determine if a word or phrase is an isogram

The task: Determine if a word or phrase is an isogram. An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed ...
7 votes
2 answers
237 views

Pretty-print dollar amounts using custom precision for large amounts

Given a floating-point number, which is representing a dollar value, I'm aiming to return a rounded, human-readable string. Here are the rules for numbers equal to or greater than 1 million, equal to ...
-2 votes
1 answer
78 views

Sorting through two dictionaries [closed]

What my code try to do here is to sort items trough 2 dictionaries. If they are similar or the same, I create a new list to append them. The test file is relatively big, around 2000 data each ...
  • 1
5 votes
2 answers
655 views

Dynamic String Alignment Code

My code works for user output alignment to the right side by maximum length of 4 different user input. I have 2 question. Is there a simplier way for append method in my code ? Is there a simplier ...
  • 137

1
2 3 4 5
10