index « 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 » index 

1. python create slice object from string    stackoverflow.com

I'd like to create a slice object from a string; right now the only way seems through a cumbersome hacky eval statement

class getslice:
    def __getitem__(self, idx): return idx[0]
eval("getslice()[%s, ...

2. Get first list index containing sub string in Python    stackoverflow.com

For lists the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the items, and not just ...

3. Python index more than once    stackoverflow.com

I know that .index() will return where a substring is located in python. However, what I want is to find where a substring is located for the nth time, which would ...

4. Python Remove Parts of string by index    stackoverflow.com

I have a string

string='texttexttextblahblah",".'
and what I want to do is cut of some of the rightmost characters by indexing and assign it to string so that string will be equal to ...

5. Finding the character occupying a particular index in a string    stackoverflow.com

I have a the string 'Hello', I need to find out what characters occupy which indexes. Pseudo-code:

string = 'Hello'
a = string.index(0)
b = string.index(4)
print a , b
a would be 'H' and b ...

6. how to insert some string in the given string at given index in python    stackoverflow.com

I am newbie in python and facing some problem , my problem is that how to insert some fields in already existing string for example: ...

7. Slicing a string in Python after looking up the index    stackoverflow.com

When we need to slice a string at a particular location, we need to know the index from where we want to. For example, in the string:

>>> s = 'Your ID ...

8. Python: find index of first digit in string?    stackoverflow.com

I suspect this is a regular expression problem - and a very basic one, so apologies. In Python, if I have a string like

xdtwkeltjwlkejt7wthwk89lk
how can I get the index of ...

9. python eval and string indexing    stackoverflow.com

Let's say I have a string

string = '1234567890'
and I want a slice of that string defined by another string
slice = '5:8'
This is easy to do with
>>>string[5:8]
'678'
However the slice is ...

10. Python: How to get the Index of a string    stackoverflow.com

How can I write a function that returns the index of a string without using the index method a.k.a string.index('some random character') Thanks in advance, Jay

11. How to use Python slice to extract a list of positions in a string    stackoverflow.com

I have two strings:

a='1234512345'

b='abcdefghik'
I would like to search string "a" for occurrences of '1' and then print the positions of "b" that correspond to that index, i.e.
'af'
I can use
import re

starts=[match.start() ...

12. Python: indexing floats?    stackoverflow.com

I have two sets of data that I am reading via nested for loops in Python. I need to match lines of the two different text files using a common ...

13. Finding a substring inside of a string and its slice?    stackoverflow.com

I've been trying to help my friend with his assignment and I can't even figure out where to start. I can get it to identify the substring inside of the ...

14. How to print password combination (but with custom constraints for each index)    stackoverflow.com

I am trying to build a dynamic password recovery tool. You can specify a password, and an unknown character list which correspond to unknown password indexes. So, if you remember 90% ...

15. Basic indexing recurrences of a substring within a string (python)    stackoverflow.com

I'm working on teaching myself basic programming.
One simple project is to find the index of recurrences of a substring within a string. So for example, in string "abcdefdef" and substring "def", ...

16. How do you use a variable as an index when slicing strings in Python?    stackoverflow.com

I've been trying to slice two characters out of a string using a loop, but instead of grabbing two characters, it only grabs one. I've tried:

input[i:i+1]
and
input[i:(i+1)]
but neither seems to work. How do I ...

17. Python List: IndexError: list index out of range    stackoverflow.com

When I try to print splited_data[1] I'm getting error message IndexError: list index out of range, On the other hand splited_data[0] is working fine. I want to insert data into MySQL. splited_data[0] ...

18. Python error message: builtins.IndexError: string index out of range    stackoverflow.com

I am creating a game where the program will read from a file that contains 5 multiple choice questions and the user can answer this questions and receive a score. However ...

19. String index out of range when converting to argparse    stackoverflow.com

I changed from optparse to argparse but when I try to run it I get the following error:

    if not option_string[0] in self.prefix_chars:
IndexError: string index out of range
My ...

20. find index number of uppercase character in a string    stackoverflow.com

string = "heLLo hOw are you toDay"
results = string.find("[A-Z]") <----- Here is my problem
string.lower().translate(table) <--- Just for the example.
>>>string
"olleh woh era uoy yadot"
#here i need to make the characters that where ...

21. string index out of range?    python-forum.org

Hey, ive been playing around with text-based RPGs, and im having trouble witha a loop. The lines giving me trouble are: Anenemy = (2, 1, 1, 0, 0, 0, 1, 1, 0, 1, 'an ememy', 1, 20) # defines stats of an enemy type enemy1 = Anenemy #defines the first enemy slot as anenemy. Exp = Exp + enemy1[12] # the ...

22. string processing / indexing difficulties    python-forum.org

def thousands(num): temp = "" rev = str(num)[::-1] for i in rev: temp += rev[i] if len(rev) > 3 and ((i+1) % 3 == 0): temp.join(',') wcom = temp[::-1] if wcom[0] == ',': ...

23. String index out of range    python-forum.org

>>> def get_odd_palindrome(word, index): ... lo, hi = index-1, index+1 ... while lo >= 0 and hi < len(word): ... if word[lo] != word[hi]: ... break ... lo, hi = lo-1, hi+1 ... return word[lo+1:hi] ... >>>

24. String index out of range    python-forum.org

import csv L = open("C:\\test.csv").read().split('\n') for line in L: # beginning of loop a = line[0] b = line[2] c = line[4] d = line[6] e = line[-1] print a, "ok", b, ...

25. why string[x:y] returns a subscript from index x to y-1?    python-forum.org

Hi All Is there any reason why string[x:y] returns a substring containing characters from index x to y-1 instead of from index x to y? I find this is very unintuitive. Thank you. and range(5, 10) is [5, 6, 7, 8, 9] and not [5,6,7,8,9,10] ? okay this is what the Python Tutorial says One way to remember how slices work ...

26. index/find usage with strings    python-forum.org

Hello, i'm writing a rather simple script, the idea is to have two strings, one containing the letters of a word, the other containing underscores with the same length (think hangman). i want to replace one of the underscores with the corresponding letter, so i made a variable called location, and assigned it to string.find(letter) and then did a simple reassignment ...

27. Help indexing strings in lists    python-forum.org

I'm writing a text adventure and working on making raw_input passable ultimately to functions that print the results of the user's input to the user. The problem I'm having is with the following code. Code: Select all #if bob=1 start at begining, if bob=2 load save. bob = [1] user_position = ['user_room'] user_says = [1] #define the command prompt. def prompt(): ...

28. [HELP]IndexError: string index out of range    python-forum.org

I'm doing an adressbook, it saves the contacts to a txt using the following pattern: Peter:Petrelli:545 Fake Av.:0695555966:1 Mohindler:Suresh:4433 Fake Av.:43567670:2 Claire:Bennet:343 Nowhere St.:34344405:3 This is: name:lastname:address:phone:id\n So as you can see I use an index number at the end of the line, and I'm doing a method to search for contacts, it will search for lines and once it founds ...

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.