All Questions

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

how to unbold a text in python? [closed]

I am trying to unbold a text using python. the text is print("the text is ",bold_item) the text is Python print("unbolded text is",unbolded_text) and the expected result is ...
user avatar
-2votes
1answer
46views

Create a List from a string in Python

I am new to pyhon and i can't find a way to manipulate a string of mine into a List. I read a file that contain this exact output (it is one parameter of a csv file): [{a,b,c},{aa,bb,cc}] I want to ...
user avatar
  • 491
-1votes
1answer
22views

Separating mixed float/string in same element in python list

I have a list like this A = [14, 15.2, '22.6g', '27.28g', '10g', '15.2R', '12.4k'] I would like to split list A it into two lists like B = [14, 15.2, 22.6, 27.28, 10, 15.2, 12.4] C = ['NA', 'NA', 'g'...
user avatar
0votes
2answers
25views

Convert String into integer value

I need to make following string: amount = "$163,852.06" Like this: 16385206000 How can I do it, like I am following this method,: money = "$163,852.06" original_amount = ('')....
user avatar
-1votes
1answer
13views

 always at beginning of string when stored to Dataframe / csv [duplicate]

Goal: prevent  from appearing in Dataframe .csv. val = f"£{format(r.randint(200, 10000), ',')}" val = '£' + format(r.randint(200, 10000), ',') val = str(f"£{format(r.randint(200, 10000)...
user avatar
1vote
2answers
17views

How to add "?" sign if the sentence type is questions

I have a list. In this list have various type of sentences suppose question type and general sentences. I want to add question mark "?" sign after end of the sentence if it it is question. ...
user avatar
1vote
4answers
40views

Casting part of a 2D list to int in Python

I have to convert all string elements of a 2-D list to integers except for the first element. For example, for a list: result = [['foo', '2', '21', '48'], ['bar', '18', '180', '54']] I only wish to ...
user avatar
0votes
0answers
15views

Wrong logical result when asking substring in string (python) [duplicate]

I know it should be a very simple matter, but i'm a bit confused. I have string: string="Facebook Posts" If i ask: ("IG" and "Post") in string The result is True. How'...
user avatar
1vote
1answer
35views

capture repeated groups in regular expressions

Similarly to this question I want to capture a group that repeats more than once. However, I don't want to use findall, because Im using the order of the evaluation of the regex. My issue - I want to ...
user avatar
-2votes
1answer
42views

regex for emoji in utf-8 python dataframe [duplicate]

i have data frame (data in file .csv) and i want to remove emoji utf-8 like '\xf0\x9f\x99\x83\xf0\x9f\x91\x8d'. i try many option but it doesnt work. i have try like this : 1. text = re.sub(r"[^\...
user avatar
0votes
1answer
25views

Find the sum and average of the numbers within a string(/sentence), ignoring all the characters

I'm new to Python but here is the pattern in which I need help to get the output Input The input will be a single line containing a string. Output The output should contain the sum and average of the ...
user avatar
  • 3
2votes
2answers
24views

I have to make a code taking a name and turning it into a last name, first initial and middle initial format

I have to make a code taking a name and turning it into a last name, first initial, middle initial format. My code works assuming there is a middle name but breaks if not provided a middle name. Is ...
user avatar
-2votes
1answer
34views

What is wrong with my Python syntax: I am trying to use multiple quotation marks plus variables in a string

I am trying to use Python to write to a file. However, the code has multiple " in it plus calls a variable. I simply cannot manage the syntax. The code should result in: { "Name of site"...
user avatar
0votes
1answer
36views

How do I organize a custom dict (with string elements)?

I receive this dict in my system, with string values, and I need to organize it in a custom way. kafka_data = { "flush_size": "1000", "branch": "develop"...
user avatar
  • 17
-1votes
1answer
33views

How can I remove one element in a json string in Python? [duplicate]

I have this payload: payload = { "cluster": "analytics", "id_pipeline": "123456789", "schema_compatibility": "backward", &...
user avatar
  • 17
-4votes
0answers
19views

String data extraction [closed]

I have the following strings with the following variable structure for each one ABDOLLAHI Hamed (a.k.a. Mustafa Abdullahi), born 11.8.1960 in Iran. Passport: D9004878. I would like to know how I could ...
user avatar
  • 1
-1votes
1answer
27views

How to find that a string/integer element is in a list or not, list is entered by user? [duplicate]

This is the code I entered l = input("Enter a list : ") lst = list(l) item = int(input("Enter an element : ")) s = len(lst) for i in range(s): if item == list[i]: ...
user avatar
1vote
2answers
66views

Replace a phrase only if it appears at the beginning of a character string [duplicate]

For example, must remove in this order "the ", "and ", "a ", "an ", "this " or "that " , only if they are at the beginning of the string: ...
user avatar
  • 107
0votes
1answer
19views

Efficient way to check if a specific character in a string appears consecutively

Say the character which we want to check if it appears consecutively in a string s is the dot '.'. For example, 'test.2.1' does not have consecutive dots, whereas 'test..2.2a...' has consecutive dots. ...
user avatar
  • 1,560
1vote
1answer
67views

Convert string of list to list of values

I have a string of a list that I am trying to convert to list, however ast.literal_eval returns an error: y = "[ { 'ake_ii': 88888, 'azefmlkh_amrlgba_dd': datetime....
user avatar
1vote
1answer
47views

Extracting the first instance of alphabetical string from an alphanumeric string in a dataframe cell

I have this dataset: NAME SUBSET Apple 48 – ABC – HH Bat 72 – ACD – HH, 72 – FI, 36 – FE – PP Cat ABC, 72 – AA – LL From this data, I want to extract only the first instance of ...
user avatar
0votes
0answers
21views

Replace string with dictionary value

I have following text file term term_1 { protocol:: tcp destination-port:: 23,24 action:: discard } term_2 { source-address:: x.x.x.x protocol:: udp action:: accept } term term_3 { ...
user avatar
1vote
1answer
41views

Why is zero-terminated bytes is not recommended in numpy.array for string?

As per NumPy offical doc: Array-protocol type strings (see The Array Interface) ... 'S', 'a' zero-terminated bytes (not recommended) 'U' Unicode string ... For backward compatibility with Python 2 ...
user avatar
  • 1,034
0votes
0answers
12views

How can i access secured str in modded str class

i saw a modded str class and i want to print my secured str which i am storing in my modded class. [see below] import sys class _SafeMeta(type): def __new__(mcs, *__): for _ in filter(...
user avatar
0votes
0answers
17views

How to put single quotes with pyformat depending on input data type?

What I'm trying to do is to use pyformat with named parameters but respect the data types of input parameters. "this is %(p1)s and this is %(p2)s" % values I would like to format this as ...
user avatar
  • 5,231
0votes
2answers
43views

Given a string, S , print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line

I know it can be simply done through string slicing but i want to know where is my logic or code is going wrong. Please Help! S=input() string="" string2="" list1=[] list1[:0]=S ...
user avatar
0votes
2answers
91views

I get TypeError: '>' not supported between instances of 'float'

I would like to get the "Ok" print of a number (B = 2 + 2) if > to number that I insert in a textbox. The first number is A = 2 + 2 A = Entry (root, width = 4, highlightthickness = 0, bg ...
user avatar
  • 99
1vote
1answer
37views

Python - indenting wrapped text

I have the following function in Python-3 def test_late_logs(tabs_data): current_date = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0) text = "*** Manual logging *...
user avatar
  • 65
-3votes
2answers
37views

removing a particular pattern from a given string in python

i would like generate the following output from the string "[cid:12d32323232dde]foo foo foo \r\n\r\n\r\n[cid:123fsr3ef234fsdfere]\r\n" expected output foo foo foo \r\n\r\n\r\n
user avatar
0votes
1answer
34views

kivy switch_to screen on if statement doesn't work

I could REALLY use your help with this one. I'm trying to make a sort-of voice command operated menu for a toddler's learning app and kivy is giving me a headache all of my screens are correctly ...
user avatar
-1votes
1answer
56views

Fill in the gaps in the initials function so that it returns the initials of the words contained in the phrase received, in upper case

#original code def initials(phrase): words = phrase.___ result = "" for word in words: result += ___ return ___ print(initials("Universal Serial Bus&...
user avatar
1vote
3answers
38views

Preserve   in beautiful soup object

I have my sample.htm file as follows: <html><head> <title>hello</title> </head> <body> <p>&nbsp; Hello! he said. &nbsp; !</p> </body> </...
user avatar
  • 13
0votes
3answers
44views

Why isn't my list elements getting casted to int?

(I wrote list instead of the actual list names for better understanding) I'm reading from a file with one number at each line. Then I made it into a list[] and I did list.append(line.replace("\n&...
user avatar
  • 11
1vote
3answers
37views

how to extract digits from column names in a pandas dataframe?

I have df.columns Index(['location', 'date', 'deaths_2020_all_ages', 'average_deaths_2015_2019_all_ages', 'deaths_2015_all_ages', 'deaths_2016_all_ages', 'deaths_2017_all_ages', '...
user avatar
  • 633
0votes
2answers
31views

How do I manipulate my string to insert individual characters of another string in Python?

I want to insert each character from one string, let's call it string A, into every other slot in another string, let's call it string B. So, for example: stringA = "abcde" stringB = "...
user avatar
-3votes
1answer
54views

Python split using multiple characters in a list

Original List : ['ValueA : 123', 'Source: 10.01, Port: 101, Destination: 10.10', 'ValueB: 4,5,6'] I want to split the value which has multiple ":" and the results should look something like ...
user avatar
  • 3,547
3votes
0answers
69views

Call multiple dictionary in a print string, first using a loop to relate subject to verb

I have this code which, thanks to a loop, relates the dictionary of a subject to the dictionary of a verb and prints it. The code works correctly. All good! The output is "Jessica è chiamatA alla ...
user avatar
  • 99
-1votes
0answers
12views

following is a program to omit all the vowels(both uppercase and lowercase) present in a string. The output is blank. What went wrong? [duplicate]

in_string = input() out_word = "" for char in in_string: if char == "a" or "A" or "e" or "E" or "i" or "I" or "o" or ...
user avatar
  • 1
1vote
1answer
57views

How to find (if it exists) that line of a txt file where the searched strings match at the same time?

I need to verify if there is a line where these 2 matches are met in the respective .txt : Line of the file named file1.txt that is equal to the input string1 "old apple". Line of the file ...
user avatar
  • 107
0votes
1answer
109views

Nested dictionary with multiple verbs which in turn have multiple verbs inside. I want to recall a verb, but I have an error

With this code I would like to print Jessica è chiamata alla prova del tris, then recall from the dictionary first the word "chiamare", then check whether to use the word "è chiamata&...
user avatar
  • 99
0votes
0answers
16views

Why does this python datetime format not convert the string of the same format into a datetime object successfully?

import datetime as dt time_str = '2022-02-25 18:37:46.594385+00:00' Then I try to convert this into a datetime object as follows: dt.datetime.strptime(time_str,'%Y-%m-%d %H:%M:%S.%f%z') However it ...
user avatar
0votes
0answers
22views

Python format dict data

I have a dictionary called dag_data and I am trying to format the different items in the list into a string using the following code: text += f"{dag_data['is_late_by']:<9} {dag_data['...
user avatar
  • 65
0votes
2answers
44views

with data of 100 row and 53 col, i want to extract the columns name which contains only true and false as data from the csv file using pandas

reducntant app kite jacker reductant2 op1 true FALSE item FALSE op2 FALSE true item4 true op3 true FALSE item2 true op4 true true ...
user avatar
0votes
1answer
18views

Is there a way to convet a user's input string into a class method name in python?

hi I've recently started working with classes in python and there is a code which I must use class for converting temperature scales . for example you choose two scales and give the temp in the first ...
user avatar
  • 13
-2votes
3answers
37views

f-string e Logical Operators OR?

I have a very simple problem that I never thought I'd encounter with the or operator and an f-string. The problem is that one of the phrase_1_random random variables is always printed. While ...
user avatar
0votes
1answer
27views

How To Find and Replace Unicode String in Python?

I have a text file containing a list of Unicode strings. Let's say list.txt and I have another dictionary file dict.txt that contains a list of words (Unicode also), which needs to be searched in the ...
user avatar
0votes
1answer
17views

How do I specify the data type of a pandas dataframe index when reading the dataframe from a .csv file?

I am creating a dataframe that has an ID Code that needs to be a string, but is often a string representation of an integer. Pandas seems to automatically convert this from the data type str to the ...
user avatar
0votes
1answer
34views

Replace every occurence in a file with a list elements - every next occurence with a list's next element

Suppose, I need to replace every 's' in the file, provided I know there are three of them, replacing every occurence on occurence-per-list-element basis: This is my test list: [1, 2, 3] Desired ...
user avatar
-1votes
1answer
31views

how to check occurance of string across two or more columns for each row and assign the final column with 0

id. datcol1 datacol2 datacol-n final col(to be created in output) 1 false true true ...
user avatar
0votes
0answers
23views

I dont understand the output of diff function from difflib module

Im having a hard time understanding the output of the Difflib module of python. This output seems fine here: import difflib from difflib import SequenceMatcher, Differ diff = Differ() test_string_1 = ...
user avatar
  • 55

15 30 50 per page
1
2 3 4 5
101