word « string « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » string » word 

1. Splitting a string into words and punctuation    stackoverflow.com

I'm trying to split a string up into words and punctuation, adding the punctuation to the list produced by the split. For instance:

>>> c = "help, me"
>>> print c.split()
['help,', 'me']
What I really ...

2. Best way to remove duplicate characters (words) in a string?    stackoverflow.com

What would be the best way of removing any duplicate characters and sets of characters separated by spaces in string? I think this example explains it better: foo = 'h k k h2 ...

3. Python strings split with multiple separators    stackoverflow.com

Weird - I think what I want to do is a fairly common task but I've found no reference on the web. I have text, with punctuation, and I want an ...

4. How do I trim the number of words in Python?    stackoverflow.com

For example...

s = 'The fox jumped over a big brown log.'

k = FUNCTION(s,4)

k should be... "The fox jumped over"
I can write my own function that splits on whitespace, cuts the list ...

5. Python: Split unicode string on word boundaries    stackoverflow.com

I need to take a string, and shorten it to 140 characters. Currently I am doing:

if len(tweet) > 140:
    tweet = re.sub(r"\s+", " ", tweet) #normalize space
   ...

6. Determine if string in input is a single word in Python    stackoverflow.com

a brain dead third party program I'm forced to use determines how to treat paths depending if the input supplied is a single word, or a full path: in the former ...

7. Splitting only long words in string    stackoverflow.com

I have some random string, let's say :

s = "This string has some verylongwordsneededtosplit"
I'm trying to write a function trunc_string(string, len) that takes string as argument to operate on and 'len' ...

8. How can I remove "word:" from a string in Python?    stackoverflow.com

I'm wondering how to remove a dynamic word from a string within Python. It will always have a ":" at the end of the word, and sometimes there's more than one within ...

9. How do I search & replace all occurrences of a string in a ms word doc with python?    stackoverflow.com

I am pretty stumped at the moment. Based on http://stackoverflow.com/questions/1045628/can-i-use-win32-com-to-replace-text-inside-a-word-document I was able to code a simple template system that generates word docs out of a template word doc (in ...

10. Using Jython, I need to randomize a string keeping the words in tact    stackoverflow.com

This is the problem: Function Name: randomSentenceRedux Parameters: 1.string – a string object to manipulate Return Value: A transformed string where the words from the original sentence are in a random order. Test Case(s):

>>>print randomSentenceRedux("My name is ...

11. Check list of words in another string    stackoverflow.com

I can do such thing in python:

list = ['one', 'two', 'three']
if 'some word' in list:
   ...
This will check if 'some word' exists in the list. But can I do ...

12. get all combinations words of a string    stackoverflow.com

i want all combinations words of string "my first program"

13. How to remove list of words from a list of strings    stackoverflow.com

Sorry if the question is bit confusing. This is similar to this question I think this the above question is close to what I want, but in Clojure. There is

14. python: how many similar words in string?    stackoverflow.com

i have ugly strings that looks like this:

   string1 = 'Fantini, Rauch, C.Straus, Priuli, Bertali: 'Festival Mass at the Imperial Court of Vienna, 1648' (Yorkshire Bach Choir & Baroque ...

15. removing /n from list of words - python    stackoverflow.com

I have a list as below ['Jellicle', 'Cats', 'are', 'black', 'and', 'white,\nJellicle', 'Cats', 'are', 'rather', 'small;\nJellicle', 'Cats', 'are', 'merry', 'and', 'bright,\nAnd', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.\nJellicle', 'Cats', 'have', 'cheerful', 'faces,\nJellicle', ...

16. Given a list of words, make a subset of phrases with them    stackoverflow.com

What is the best way performance wise to take a list of words and turn them into phrases in python.

words = ["hey","there","stack","overflow"]
print magicFunction(words)
>>> ["hey","there","stack","overflow", "hey there stack","hey there", "there stack ...

17. How to do a Python split() on languages (like Chinese) that don't use whtespace as word separator?    stackoverflow.com

I want to split a sentence into a list of words. For English and European languages this is easy, just use split()

>>> "This is a sentence.".split()
['This', 'is', 'a', 'sentence.']
But I also need ...

18. Split string by number of words with python    stackoverflow.com

How do I split up a string into several parts of a number of words in python. For example, turn a 10,000 word string into ten 1,000 word strings. Thanks.

19. Python: translating/replacing in a string words that aren't the ones you want    stackoverflow.com

Basically, I've got a bunch of phrases and I'm only interested in the ones that contain certain words. What I want to do is 1) find out if that word is ...

20. nth word in a text    stackoverflow.com

how can I find the nth word in a text. example:

my_txt("hello to you all" , 3)

all
I don't wanna use any built in function ...and this is not a homework :D

21. in string, capitalize allcaps words and leave the rest alone    stackoverflow.com

For example, having gone through this procedure the string:

Hello, WORLD, McGisty, you are my HERO THAT I am.
should return/be:
Hello, World, McGisty, you are my Hero That I am.
Thanks!

22. Remove all articles, connector words, etc., from a string in Python    stackoverflow.com

I have a list that contains many sentences. I want to iterate through the list, removing from all sentences words like "and", "the", "a", "are", etc. I tried this:

def ...

23. Python- The Word Game "Ghost", File I/O, and List question    stackoverflow.com

I want to create computer for the word-game Ghost. However, I'm having problems thinking of a good way to deal with accessing the huge word list. ...

24. python search technology: word similarity    stackoverflow.com

I want to get a similarity percentage of two words, eg)

abcd versus zzabcdzz == 50% similarity
Don't need to be very accurate. Is there any way to do that? I am using ...

25. python string u"%(word)s"    stackoverflow.com

i'm a new user of python , i don't know some place when i read the code . so i asked here.

cmd = u"sudo umount %(mountpoint)s >>%(log)s 2>&1"
i know that %(word) ...

26. Finding the most popular words in a list    stackoverflow.com

I have a list of words:

words = ['all', 'awesome', 'all', 'yeah', 'bye', 'all', 'yeah']
And I want to get a list of tuples:
[(3, 'all'), (2, 'yeah'), (1, 'bye'), (1, 'awesome')]
where each tuple ...

27. Python - Check If Word Is In A String    stackoverflow.com

I'm working with Python v2, and I'm trying to find out if you can tell if a word is in a string. I have found some information about identifying if the word ...

28. Python - Optimal code to find preceding and following five words from a given point in a line    stackoverflow.com

I'm trying to write code to find the 5 words on either side of a particular phrase. Easy enough, but I have to do this on a massive volume of data, ...

29. Python: Splitting a string into words, saving separators    stackoverflow.com

I have a string:

'Specified, if char, else 10 (default).'
I want to split it into two tuples
words=('Specified', 'if', 'char', 'else', '10', 'default')

separators=(',', ' ', ',', ' ', ' (', ').')
Does anyone ...

30. Deleting words that appear multiple times in a file    stackoverflow.com

How can I delete words that appear multiple times in a file and just keep the first one and delete the clones.

31. Converting a String to a List of Words?    stackoverflow.com

I'm trying to convert a string to a list of words using python. I want to take something like the following:

string = 'This is a string, with words!'
Then convert to something ...

32. Python: Adding a word from a stringlist to another stringlist    stackoverflow.com

I'm trying to add whole words from one string to another if they contain a certain character:

mylist = ["hahah", "hen","cool", "breaker", "when"]
newlist = []

for word in mylist:
    store ...

33. ?Breaking a string into individual words(Python)    stackoverflow.com

I have a large list of domain names (around six thousand), and I would like to see which words trend the highest for a rough overview of our portfolio. The problem I ...

34. splitting unicode string into words    stackoverflow.com

I am trying to split a Unicode string into words (simplistic), like this:

print re.findall(r'(?u)\w+', "??? ??? ???")
What I expect to see is:
['???','???','???']
But what I really get is:
['\xd1', '\xd0', '\xd0', '\xd0', '\xd0\xb2\xd0', ...

35. Python: Deleting specific strings from file    stackoverflow.com

I have a data file (un-structed messy file) from which I have to scrub specific list of strings (delete strings). Here is what I am doing but with no result:

infile = ...

36. string.title() thinks apostrophe is a new word start. Why?    stackoverflow.com

>>> myStr="madam. i'm adam! i also tried c,o,m,m,a"
>>> myStr.title()
"Madam. I'M Adam! I Also Tried C,O,M,M,A"
This is certainly incorrect. Why would an apostrophe be considered be considered as the start of a ...

37. Python - Remove duplicate words in string    stackoverflow.com

Following example:

string1 = "calvin klein design dress calvin klein"
how can I remove the second two duplicates "calvin" and "klein"? result should look like -> string2 = "calvin klein design dress" only the second ...

38. Don't split double-quoted words with Python string split()?    stackoverflow.com

When using the Python string function split(), does anybody have a nifty trick to treat items surrounded by double-quotes as a non-splitting word? Say I want to split only on white space ...

39. Python - finding words based on repeated characters specified in a string    stackoverflow.com

Let's say I have a list of words: resign resins redyed resist reeded I also have a string ".10.10" I need to iterate through the list and find the words where there are repeated characters in the same ...

40. Python: detect strings that share words    stackoverflow.com

I have a list of single and multi-word phrases: terms = ['Electronic rock', 'Alternative rock', 'Indie pop'] I want to detect that terms[0] and terms[1] share the word rock. Is there a Pythonic ...

41. How do I calculate the number of times a word occurs in a sentence? (Python)    stackoverflow.com

So I've been learning Python for some months now and was wondering how I would go about writing a function that will count the number of times a word occurs in ...

42. how to delete lowercase words from a string in python    stackoverflow.com

I'm new in python and I'm having some issues doing a simple thing. I've an array (or list as it's said in pyton) like this:

 list = [ 'NICE dog' , 'blue ...

43. Check word in string.    python-forum.org

def in_string(string, value, poss = None): items = string.split() if value in items: if poss: if items.index(value) == poss: ...

44. parsing strings for words in a text file    python-forum.org

Hello, I have a list of strings in a text file. I have a second text file that contains dictionary words. I would like to parse the strings in the first text file to see if any of the dictionary words are present in the strings. I can do a compare with no problem. What I need to do is see ...

45. [solved] Wildcardify a word (string.replace())    python-forum.org

std::vector wildcardify(std::string word) { std::vector result; result.push_back(word); result.push_back("*"+word); result.push_back(word+"*"); for (unsigned int c=1; c < word.length(); c++) for (unsigned int i=0; i <= word.length()-c; i++) result.push_back(std::string(word).replace(i, c, "*")); return result;

46. occurence of words in a string    python-forum.org

occurence of words in a string by yogi Thu May 20, 2010 3:42 pm Hi there I try to write a programme that counts the occurrence of words in a string. I found a way to do so but if the word appear 10 times in the text it will write the word and its occurrence 10 times. Do you ...

47. Replace word in string    python-forum.org

sentence = 'Hello, his name is Bart.' list = ['his', 'their'] list2 = ['her', 'our'] What I want to do is to search through 'sentence' to see if any of the words in 'list' is in it. If so, I want to replace that word with the word from the same element in 'list2' or vice versa. So it should look ...

48. Help getting each word from a string    python-forum.org

49. splitting a string by words and phrases?    python-forum.org

50. Using .title() on a string while keeping certain words lower    python-forum.org

Code: Select all STOPWORDS = 'and i a as are at of the'.split() # Add to the list as appropriate def correcttitle(): title = raw_input('Enter the title of the article >') newtitle = [] # Look at each word for word in title.split(): ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.