Tagged Questions
0
votes
0answers
26 views
String formatting length
i found a strange behaviuor in my code.
I am trying to build a string to send a command to the OS, like this:
cmd = "curl -H \"{0}\" -H 'Accept: application/metalink4+xml' bla bla ...
0
votes
2answers
28 views
Python split and manipulate results
What is the pythonic way of code below, which was basically copied from php?
def get_extra_info(self, info):
extra = []
for i in info.split(';'):
t = i.split(':')
extra[t[0]] ...
0
votes
3answers
21 views
Convert string string to datetime object
My string is ,
str='2014-09-24T15:18:57+0000'
and I am trying to convert this string to valid datetime object. How to do that ?
What I tried is ,
>>> from datetime import datetime
...
-3
votes
0answers
32 views
Combine a hex tuple
I have a hex tuple of ('00', '17', '0d', '00', '00', '38', '1d', 'ab')
I would like to combine it into one string: '00-17-0d-00-00-38-1d-ab'
Not having much luck with the join command.
Edit
The ...
1
vote
5answers
44 views
print sum of strings as float
I am working on an exercise that states:
Let s be a string that contains a sequence of decimal numbers
separated by commas, e.g., s = '1.23,2.4,3.123'. Write a program that
prints the sum of ...
-1
votes
6answers
42 views
Counting the number of times a word appears in a string? [on hold]
I need to write a simple script to print the number of times the word 'a' appears in a string. If I use s.count it searches for the letter and not the word. My string is:
s='This is a sentence with a ...
0
votes
3answers
22 views
Python - Split String with Parenthesis based off a Pattern
I have a problem in python where I have a pattern, that can repeat anywhere from 1 to XXX times.
The pattern is I have a string of format
Author (Affiliation) Author (Affiliation) etc etc etc as ...
0
votes
3answers
37 views
How write a regex that preserve the order of appearence with python?
Given the following string i would like to extract a tuple such that the tuple preserve the appeareance of an assosiated id (POS tag). The order is: NCFS000, AQ0CS0. They need to be concecutive, no ...
-1
votes
1answer
31 views
Finding element by a variable
I'm trying to select an element from a dropdown list. The element is defined by its value, which is a date. For this example, let's say the date that I'm trying to select is today. The element's value ...
-1
votes
0answers
63 views
Does this python code require more optimisation?
While I was working with my task I came across the below scenario:
Given two arbitrarily sized strings, I want to know if:
Any part of string “A” is contained in string “B”
What substrings are ...
0
votes
4answers
45 views
Python how to split a string into words that contain words with a single quote?
I have a string a, I would like to return a list b, which contain words in a that not starts from @ or #, and not contains any non-word characters.
However, I'm in trouble of keep words like ...
0
votes
0answers
18 views
C++ vector of strings to Python 3.4 and array of objects back
I have a Windows application that is written in C++. I have a vector of strings that I need to pass to a python Script for processing. I know how to embed python in C++ with simple type but I am ...
2
votes
4answers
86 views
How to change only a specific letter at a specific index in a string to uppercase/lowercase
Here is the code:
def upper_every_nth (s, n):
i = 0
while len (s) > (i * (0 + n)) :
character = s[i * (0 + n)]
s = s.replace(character, character.upper(), 1)
i = i ...
-1
votes
0answers
49 views
How to get string in a function in Python?
I am current writing a game with tkinter GUI Python.
import sys
from tkinter import*
#Functions to handle button click
def startgame():
player21abel=Label(text=" Guess a Letter ...
0
votes
2answers
52 views
Splitting Array into Strings and Displaying Python
So, I'm trying to take information from bookfile.txt and display information from it. So far, I've opened the file. I'm having trouble getting each line as one object of arrayBooks.
I'd like to have ...
2
votes
2answers
30 views
Understanding strip()
I am trying the strip() method on this string but it doesn't give the desired output.
s = 'www.yahoo.com'
s = s.rstrip('.com')
print s # The desired output is 'www.yahoo' but this is showing ...
0
votes
3answers
66 views
List of ints to string
I have a list of ints:
(83, 105, 101, 109, 101, 110, 115)
which I believe codes for Siemens.
How can I convert this list to a string in a pythonic way?
I know I can get the individual chars with ...
0
votes
2answers
20 views
Accessing PIL image subelements, and taking a string from it
At the moment i have an image that i would just like to sample a single string out of the example outlines the details below (Assume the image has been loaded into memory for PIL access)
# Image size ...
-6
votes
0answers
123 views
Writing python string (python newb) [on hold]
def upper_every_nth(s, n):
'''(str, int) -> (str)
Return a string that is identical to s except that every nth character (starting at position 0) is uppercase.
>>> ...
0
votes
2answers
29 views
Findin a pattern in a string with loops in python
I'm trying to write a function that will determine whether a given pattern exists in a given string. For example "abc" in "afewtabcks"
To do this, I have written a main function that will prompt for ...
-2
votes
1answer
25 views
How do i find a string within a string in Python?
I'm working on a Mad-Libs assignment for class.
Essentially I need to isolate a {blank} in a string and print that as a prompt. I then need to return that input to where the blank used to be. This ...
0
votes
0answers
27 views
Solve system of a set number of equations
I'm attempting to make a code that will solve a set of nonlinear equations depending on a user input, n. Where n is the number of stages in a separation and with each n there are n+1 degrees of ...
0
votes
3answers
45 views
Python: list iteration works but single string doesn't
I'm very new to Python and am working my way through the "Learn Python The Hard Way" web tutorial. But I've come to a halt as I have an issue with passing a single string. I'm able to pass a list ...
-3
votes
3answers
59 views
How to extract a number from a string in Python?
How do you extract a number from a string to be able to manipulate it? The number could be either an int or a float. For example if the string is "flour, 100, grams" or "flour, 100.5, grams" then ...
-3
votes
0answers
32 views
Python Search for WHOLE words [duplicate]
I am running Python V2.7
I would like to pinpoint a whole word in a string, but I am having troubles. I have tried using the in statement but no luck. Heres and example:
if "word" in "Sword" # This ...
0
votes
3answers
24 views
How to combine variables with Python
This is my problem:
def encrypt(mult1, mult2):
encrypted = mult1 * mult2
print (encrypted)
encrypted_message = mult1, encrypted, mult2
print (encrypt_key)
return encrypt_key
...
0
votes
1answer
27 views
Python Conditional Password Program
I'm writing a simple conditional password checker script with the conditions being:
> 8 characters
< 24 characters
No special characters
At least two upper case letters
At least two lower case ...
-1
votes
1answer
37 views
Python simple string cycle
What it should look like:
enter word: word
enter number: 5
word
word+word
word+word+word
word+word+word+word
word+word+word+word+word
What I had:
for i in range(1,number+1):
print(word*i)
...
13
votes
1answer
314 views
How does \v differ from \x0b or \x0c?
Typing string.whitespace gives you a string containing all whitespace characters defined by Python's string module:
'\t\n\x0b\x0c\r '
Both \x0b and \x0c seem to give a vertical tab.
>>> ...
-3
votes
1answer
24 views
need help. python integers and strings [duplicate]
I have been having some issues with a line of code in a program I'm making. when ever I run the file it displays this message:
Traceback (most recent call last):
File "C:\Users\Main\Google ...
-4
votes
2answers
37 views
Python - How to get string in a Function?
I am currently writing a hang man game. Using Tkinter for GUI.
How can I get a string from a function:
def startgame():
player21abel=Label(text=" Guess a Letter ...
0
votes
2answers
25 views
Getting ambiguous truth value for string in for loop and not sure why
I have a list of strings called my_strings. I want to pull out all strings within that list that contain search_string
My attempt is the following:
new_strings = [my_str for my_str in my_strings if ...
0
votes
1answer
41 views
python string formatting {:d} vs %d on floating point number
I realise that this question could be construed as similar to others, so before I start, here is a list of some possible "duplicates" before everyone starts pointing them out. None of these seem to ...
-1
votes
1answer
24 views
Converting user input to binary and back in Python 3
I'm trying to create a program that will take a user's input, such as a URL that contains numbers, symbols, and letters and converts it into a string of binary. I've tried looking up string to binary ...
0
votes
6answers
48 views
Replacing parts of strings in a list in Python
I know similar questions exist for this topic but I've gone through them and still couldn't get it.
My python program retrieves a subsection of html from a page using a regular expression. I just ...
0
votes
1answer
56 views
Search and replace between two files with search phrase in first file: Python
File 1:
$def String_to_be_searched (String to be replaced with)
File 2:
..... { word { ${String to be searched} } # each line in File 2 is in this format
..... { word { ${String} } # This line ...
1
vote
2answers
76 views
python: how can I read elements of 2d dynamic lists?
I have following data
['1', '4', '4', '244', '263', '704', '952']
['2', '4', '4', '215', '172', '305', '33']
['3', '4', '4', '344', '279', '377', '1945']
['4', '4', '4', '66', '79', '169', '150']
...
-3
votes
1answer
28 views
Count Consonants Before First Vowel in a String
I'm creating a simple pig Latin translator. Here's what I have so far:
while True:
phrase = input('Translate > ').lower().split()
for word in phrase:
if word[0] in 'aeiou': #if the ...
0
votes
3answers
37 views
Python: Split string at the start of delimiter rather than the end
I'm trying to split a string using a multiple character delimiter, I can keep the delimiter in the result, but it is in the first part rather than the second part where I need it. This is what I have.
...
0
votes
1answer
22 views
i cannot get rid \xa0 in this string using python?
here is the code:
shipping_info = u'Expedited (2-3 Bus. Days)\xa0($17.99)'
I cannot get it to replace \xa0 using the method like replace.
here is what i tried:
x.replace('\\xa0', ' ')
...
-4
votes
5answers
61 views
Python - split a string into sets of twos
I want to split a string into sets of twos
eg.
['abcdefg']
to
['ab','cd','ef']
thanks
here is what i had so far:
string = 'acabadcaa\ndarabr'
newString = []
for i in string:
...
-1
votes
1answer
27 views
Match repeating characters from set
from re import search
import random
while True:
r = ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(random.randint(1, 100)))
if ...
-2
votes
1answer
30 views
Python - Print last string after line.split
Is there a easy way to print the last string after you've split?
Input File:
Name:DOB:Age
Name:Name2:DOB:Age
I want the name and age...
So...
string = line.split(':')
print(string[0] + ...
-2
votes
3answers
28 views
How can I make a list of a input string the user has typed into Python?
I'm new in programming and in my script I have to create a list with a input string y the user.
I know how basic of slicing works and making a list ex: list = []
but I need to write the code so ...
0
votes
2answers
67 views
Capitalize the first letter in a string? [duplicate]
I have to to capitalize the first character of a word without lowering any letters.
I've tried using title() and capitalize() but they change the whole word by lowering the capitalized letter(s).
...
-1
votes
2answers
27 views
Compare strings in python like the sql “like” (with “%” and “_”)
I have a list in python with some strings, and I need to know witch item in the list is like "A1_8301". This "_" means that can be any char.
Is there a quick way to do that?
If I was using SQL, i ...
-1
votes
1answer
40 views
Filter a list of tuples by pairwise pattern [closed]
I have the following string, wich is full of a word and it´s parts of speech:
[('lavadora', 'NCFS000'), ('sencilla', 'AQ0FS0'), ('facilidad', 'NCFS000'), ('casa', 'NCFS000'), ('marca', 'NCFS000'), ...
1
vote
5answers
48 views
Merging (logical OR) together the contents of two 'bitmaps' in strings
I've got two strings that contains 'bitmaps' of weekdays: for example, 1------ is Monday only, --3-5-- is Wednesday and Friday, you get the idea.
I'd like to merge these together with the equivalent ...
-1
votes
5answers
52 views
Check that two characters are not adjacent in Python
In my program, I need to check a user-input equation to make sure that it's a valid equation. I got rid of any operators at the beginning or end by using myEquation[0].isdigit and ...
3
votes
2answers
43 views
Efficiently read data in python (only one line)
For a upcoming programming competition I solved a few of the tasks of former competitions.
Each task looks like this: We get a bunch of in-files (each containing 1 line of numbers and strings, f.e. ...