Hi everybody
I am searching for a possibility, to find out, what the index for a
certain lettyer in a string is.
My example:
for x in text:
if x == ' ':
list = text[: # There I need the index of the space the
program found during the loop...
Is there and possibility to find the index of the space???
Thanks for any help!
Fred 4 1241
Fred wrote: I am searching for a possibility, to find out, what the index for a certain lettyer in a string is. My example:
for x in text: if x == ' ': list = text[: # There I need the index of the space the program found during the loop...
Is there and possibility to find the index of the space??? Thanks for any help! Fred
Use the index method, e.g.: text.index(' ').
What exactly do you want to do?
-pu
Fred wrote: Hi everybody
I am searching for a possibility, to find out, what the index for a certain lettyer in a string is. My example:
for x in text: if x == ' ': list = text[: # There I need the index of the space the program found during the loop...
Is there and possibility to find the index of the space??? Thanks for any help! Fred
Perhaps you need something at a higher level (though you could use
text.find(" ") for the first occurrence). I suspect you might want
split(). Fred, meet split(). split(), meet Fred. s = "The quick brown python swallows the lazy mongoose" s.split()
['The', 'quick', 'brown', 'python', 'swallows', 'the', 'lazy', 'mongoose'] s.split(None)
['The', 'quick', 'brown', 'python', 'swallows', 'the', 'lazy', 'mongoose'] s.split(None, 3)
['The', 'quick', 'brown', 'python swallows the lazy mongoose'] s.split(None, 1)
['The', 'quick brown python swallows the lazy mongoose']
regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
> Use the index method, e.g.: text.index(' '). What exactly do you want to do?
That was exactely what I was searching for. I needed a program, that
chopped up a string into its words and then saves them into a list. I
think I got this done...
Thanks for the help
Fred wrote: That was exactely what I was searching for. I needed a program, that chopped up a string into its words and then saves them into a list. I think I got this done...
There's a function for that: text.split().
You should really have a look at the Python docs. Also, http://diveintopython.org/ and http://www.gnosis.cx/TPiP/ are great
tutorials.
-pu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hilde Roth |
last post by:
This may have been asked before but I can't find it. If I have
a rectangular list of lists, say, l = ,,], is
there a handy syntax for retrieving the ith item of every sublist?
I know about for i...
|
by: Matt |
last post by:
Hello, I was wondering if anyone could suggest a way of doing the
following in Python: I'm writing a class to handle strings of bits,
and I often need to number the bits in different ways, e.g....
|
by: Ishwor |
last post by:
Hi all. Look at this snippet of code.
>>> l =
>>> l
>>> l
'a'
It prints the value 'a'. Fine so far :-)
l ---> 'a' .
l---> 'a' --> 'a'.
|
by: Bryan Olson |
last post by:
The Python slice type has one method 'indices', and reportedly:
This method takes a single integer argument /length/ and
computes information about the extended slice that the slice
object would...
|
by: Ryan |
last post by:
I have a bit of a problem with regards an indexing strategy. Well,
basically there is no indexing strategy on a set of data I have at
work. Now, I didn't create the design as I would have allowed...
|
by: Chung Leong |
last post by:
Here's the rest of the tutorial I started earlier:
Aside from text within a document, Indexing Service let you search on
meta information stored in the files. For example, MusicArtist and...
|
by: jacob navia |
last post by:
Suppose an implementation where
sizeof int == 4
sizeof void * == 8
sizeof long long == 8
When indexing an array
array
this would mean that arrays are limited to 2GB. To overcome this,
|
by: Emin |
last post by:
Dear Experts,
How much slower is dict indexing vs. list indexing (or indexing into a
numpy array)? I realize that looking up a value in a dict should be
constant time, but does anyone have a...
|
by: Server Applications |
last post by:
Hello
I am trying to build a system where I can full-text index documents with
UTF8 or UTF16 data using Oracle Text. I am doing the filtering in a
third-party component outside the database, so...
|
by: =?Utf-8?B?SmVycnkgQw==?= |
last post by:
I have a server 2008 IIS 7.0 with indexing service installed.
I have created the catalog and have a test page using these posts:...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |