0
votes
1answer
25 views

Python won't rewrite file with first line removed using readlines() and for loop

I' writing a web scraping script in Python that pulls an 'ID' from the first line of a text file and appends it to a partial URL; then downloads an image from said URL. Everything works fine, but when ...
0
votes
3answers
40 views

Convert string to int value python

I want to convert a string to a specific int value in Python i.e. "red" I want to be 1, "blue" to 2, etc. I am currently using if-else statements. I have a dataset of strings with common strings that ...
0
votes
4answers
33 views

Printing list into fixed width strings in Python

With the following list" In [3]: entr = [ 'ATOM', '1', 'P', 'C', 'B', '3', '42.564', '-34.232', '-7.330', '1.00', '105.08', 'P' ] I'd like to create a string with fixed width using %. But why this ...
0
votes
5answers
29 views

Python: how to escape “%s”

I'm trying to make a string that includes a "%s" with no formatting For example, I want this: #I want to make mystring = "x %s" first_value = "x" mystring = "%s %s" % first_value So, I want to ...
0
votes
1answer
23 views

Python hex string operation: need to preserve the leading zeros

I have two numbers: a = "00000108" b = "FFFFF9FF" I want to compute the bitwise AND of the hex values in the two strings. The result I want is a string: "00000108" Here is what I have come up ...
0
votes
1answer
19 views

How to use string kernels in scikit-learn?

I am trying to generate a string kernel that feeds a support vector classifier. I tried it with a function that calculates the kernel, something like that def stringkernel(K, G): for a in ...
2
votes
5answers
35 views

Using max() on a list that contains numbers and strings

I have a list that is like this: self.thislist = ['Name', 13, 'Name1', 160, 'Name2', 394] Basically the list has a name and a number after it, and I'm trying to find out the highest number in the ...
-1
votes
1answer
37 views

Python ANY operator comparing strings

Question I am writing a program that should scrape HTML and search if any strings are in the url's i just downloaded. How can i achieve this? My Any Operator only seems to catch on to the first ...
0
votes
1answer
39 views

Most efficient way to strip a % from u'96.9%' and return a float

Let's say I run a BeautifulSoup strainer and get some unicode back like u'96.9%' and I want only the numeric values (and the decimal) to get printed out to a file. It seems pretty straightforward to ...
1
vote
2answers
48 views

Getting Python to return a list of strings randomly from a given string

import random def create_code(characters): return list(random.choice(characters)*4) if __name__ == '__main__': characters = 'ygobpr' print create_code(characters) # how do i get python ...
0
votes
3answers
27 views

Python searches CSV for string in one column, returns string from another column in the same row

I'm attempting to write a program in python that searches ~27,000 rows for each string in a list. Each string I am searching for is in one column, and has an 'id' value in another column that I would ...
0
votes
5answers
44 views

Python Program that gets stuck on the first number entered

This is my code so far. word = input('Enter a word: ') count = 0 vowels = ['a' , 'e' , 'i' ,'o' , 'u'] for char in word: if char in vowels: count += 1 while word != "": print(word + ...
-2
votes
1answer
31 views

Python error: string index out of range

I try to update a game of n in a row. But when i try to update the array matrix i get the "string out of range error. I made a while statement with ind < len(board_height). What am I doing wrong ...
-5
votes
2answers
35 views

Beautiful way to wrap string with quotes in python [on hold]

I have two ways.. "'" + 'hello' + "'" and "'%s'" % 'hello' But not beautiful, Do you have any idea ?
0
votes
1answer
17 views

extract all lines after new line with regex python

i have this string: Packages: Package [com.bizportal] (42662eb0): userId=10086 gids=[3003] pkg=Package{42c3b300 com.bizportal} codePath=/data/app/com.bizportal-1.apk ...
-1
votes
5answers
60 views

Python Coding for Reversing Sentences

this is the code i am using so far. translated = [] line = input('Line: ') while line != '': for word in line.split(): letters = list(word) letters.reverse() word = ''.join(letters) ...
1
vote
3answers
28 views

Replace a certain index of a string in python 3.0

I need to replace a character in a string but here is the catch, the string will be all underscores and I need to be able to replace the underscore that corresponds to the index of the word. For ...
1
vote
1answer
46 views

how to print the equal sign in python

I'm trying to print an equal sign (=) in Python, using this code: num= int(raw_input('Please enter a number: ')) num2= int(raw_input('Please enter another number: ')) print '%s + %s' % (num, num2), ...
0
votes
3answers
50 views

Why keep on converting from string to list back and forth?

I have a text file containing all the students' names and other information of my programing course like this: Smith, John [email protected] [email protected] Student Lester, Moe [email protected] ...
0
votes
0answers
9 views

Does PyString_AS_STRING work different in Windows 64 bits vs 32 bits?

I have the following function: void py_get_var( const char** var_name, int* found, char** resultado ) { *found = 0; PyObject * module = PyImport_AddModule("__main__"); PyObject * ...
0
votes
1answer
11 views

creating a representation of an object when no string to work with (python, django)

i'm using the django tutorial (which i've done earlier) to create a simple timesheet app and struggling to understand the str method. works fine for the Project class because i have string name, but ...
0
votes
1answer
35 views

python - take a string and dictionary and return an encrypted version of the string

encrypt the string with the dictionary so that it returns kjyyp def encrypt(s,d) d = { 'a' : 'm', 'b' : 'd', 'c' : 'l', 'd' : 'x', 'e' : 'j', 'f' : 't', 'g' : 'u', 'h' : 'k', 'i' : ...
1
vote
2answers
49 views

How to store a set of string space efficiently

Assume we have a set of string {"abc","def","ghia"} What is the space efficient way to store the string? In addition, given an input string like "abc" or "abc1", I need find out whether "abc"(yes) ...
0
votes
1answer
29 views

Convert a string with list syntax into list(s)

I am trying to convert a string into lists. The structure of the string (of which I have a database full of them) is always that of n lists within a list. However, I have them in string format. ...
-1
votes
2answers
37 views

Python Program with Ending Error

I am currently using this code word = input('Enter a word: ') count = 0 vowels = ['a' , 'e' , 'i' ,'o' , 'u'] for char in word: if char in vowels: count += 1 if count == 1: ...
-1
votes
1answer
36 views

Find specific values in a text file and write these strings to a new file

How can I find specific value in file with text and write these lines to the file (not only strings to the file, but all lines where are these strings)? I have something like this (but it finds only ...
-1
votes
3answers
80 views

How to remove duplicate element in list?

The assignment says: Write a Python program that reads in a sentence. The program converts the string (that the user input) to a list and prints the sentence as a list of string objects. The program ...
0
votes
5answers
85 views

Python - check if a letter is in a list

If a letter (string) is in a list, find_letter(['o', ['hello', 'c', 'bye']), return True, if not return False. def find_letter(lst): lst=['o','hello', 1] n='o' if not lst: ...
-2
votes
3answers
26 views

How to match keys in a list and find there intersecting values?

i have a dictionary with lists and my goal is to match a query list against the dictionary and for matched terms display there intersecting values. For example dict= [(this, ['1']), (word, ['1', ...
0
votes
3answers
41 views

Compare a permutation to list of words - Python

I'm trying to compare the output of a permutation of a string to a txt with pretty much every word in the dictionary. The function itself is an anagram solver. The function takes word as a parameter. ...
0
votes
1answer
27 views

Generator not working to split string by particular identifier . Python 2

So far I have found a way to yield the name, string, and extra string. It works for the second one but does not work for the first one? it's so weird because the formats are really similar. is it ...
0
votes
3answers
34 views

Replacing Certain Parts of a String Python

I can not seem to solve this. I have many different strings, and they are always different. I need to replace the ends of them though, but they are always different lengths. Here is a example of a ...
1
vote
3answers
23 views

iterate through list while looking for matching elements from a different list in python

I have a list of some random strings ex: list_test = ["adam", "adam", "lori", "conrad", "lori", "adam"] Then i also have two lists, one that i want to test for matches agains and one that will ...
-2
votes
0answers
17 views

Converting a list of mixed elements to a string in Python [duplicate]

I have tried different ways to convert a list of mixed elements in the form of a = ['hello', '123456', 20, 5] to a desired string b = 'hello, 123456, 20, 5' but so far haven't been able to.
-4
votes
0answers
40 views

How can I convert multiple strings to uppercase, separated by enter? [on hold]

Converting a string to uppercase isn't a problem for me, but I want to convert multiple strings to uppercase, separated through Enter and when the user writes 'stop' and hits Enter it should convert ...
-4
votes
1answer
50 views

How to replace strings in a string

I have a text string. I need to decode the text string i.e, replace every character in the string with its counterpart and then read the message. How do I achieve this? For example: g fmnc wms ...
2
votes
1answer
42 views

A smarter & faster way to convert numpy ndarray to string in python

I have my geographical coordinates of rectangles represented as numpy ndarray like this: (each row corresponds to a rectangle and each column contains its lower left and upper right longitudes and ...
1
vote
2answers
24 views

Why does the Output for a MySQL Connecter Query return as a nested list item?

Why does this print into a list and not just as a string? import mysql.connector from mysql.connector import errorcode config = { 'user': 'user', 'password': 'xxxxx', 'host': '127.0.0.1', ...
1
vote
5answers
41 views

operating with string, list & dictionaries

I have a list & a dictionary. l = ['one', 'two', 'three', 'four'] d = {'aw.one' : '#aw.one', 'aw.two' : '#aw.two'} Now, I have a string : s = "this is one sentence" I want to check if any ...
0
votes
1answer
30 views

Returning a string from a Python function

def God(): set_path() find_files(path) def set_path(): '''Sets file path to inputted directory''' # Should path default to a certain directory if path is invalid? # (it does ...
1
vote
2answers
36 views

float value in a string to int in Python

Why isn't it possible to directly convert a floating point number represented as a string in Python to an int variable? For example, >>> val=str(10.20) >>> int(val) Traceback (most ...
1
vote
3answers
32 views

Python regex delimiting a string

[Answered first part, please scroll for second question edit] Currently coding a web scraper in python. I have the following example string: Columbus Blue Jackets at Buffalo Sabres - 10/09/2014 I ...
-3
votes
1answer
26 views

extracting data from formatted string (python)

I have a string like this: (63, 166) - (576, 366) I need to extract the values out so that I have: x1 = 63 y1 = 166 x2 = 576 y2 = 366 I can easily use the split() function and save the results ...
-6
votes
1answer
31 views

List and strings [on hold]

how do i write a function in python that, given two parameters of which one is a string text and one is a list of strings, the function counts the occurrences of the strings contained in the list in ...
0
votes
2answers
32 views

Detecting whether a string contains non-letters

How can I write a function that detects whether a string has non-letter characters in it? Something like: def detection(a): if !"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" in a: ...
0
votes
1answer
32 views

Script to remove all files from a text file

I am creating a script that will copy all files mentioned in a text file to some destination. This is my script: with open('names.txt') as f: for line in f: a = 'cp ' + line + ' ...
1
vote
3answers
36 views

Capitalization of each sentence in a string in Python 3

This should be easy but somehow I'm not quite getting it. My assignment is: Write a function sentenceCapitalizer that has one parameter of type string. The function returns a copy of the ...
-2
votes
3answers
50 views

Count most frequent [on hold]

I want to count most frequent string that i have in a list, but the list that i am trying to access is the return output of another function. Is there a way that i can call the function with a list ...
0
votes
2answers
29 views

How to loop thru a json strings and convert them to datetime objects?

I have a json file with the following content, and I want to convert its string values to date time object: ["2014-01-20 00:01:31", "2014-01-20 00:01:51", "2014-01-20 00:02:12"] I think I need to ...
2
votes
2answers
55 views

What does 'r' mean before a Regex pattern?

I found the following regex substitution example from the documentation for Regex. I'm a little bit confused as to what the prefix r does before the string? ...