473,594 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Indexing strings

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
Jul 18 '05 #1
4 1253
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
Jul 18 '05 #2
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/
Jul 18 '05 #3
> 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
Jul 18 '05 #4
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
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4305
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 in l] but I was hoping for something more like l. Hilde
0
916
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. from the left starting at zero, or from the right starting at one, and so forth. I'd quite like to be able to dynamically change how subscripting works for individual objects, and maybe have that behaviour transferred to any further objects that...
10
2040
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'.
108
6354
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 describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the /start/ and /stop/ indices and the /step/ or stride length of the slice. Missing or out-of-bounds indices are handled in a manner...
7
1815
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 for this. OK, so there is primary key (clustered) indexes (mainly composite keys), but no other indexes on the tables. As you would expect, the performance leaves a lot to be desired. A hell of a lot. We have several million rows in a lot of the...
3
9544
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 MusicAlbum let you find MP3 and other music files based on the singer and album name; DocAuthor let you find Office documents created by a certain user; DocAppName let you find files of a particular program, and so on. Indexing Service uses plug-ins...
26
410
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,
4
11598
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 sense of what the overhead will be in doing a dict lookup vs. indexing into a list? Some ad hoc tests I've done indicate that the overhead is less than 15% (i.e., dict lookups seem to take no more than 15% longer than indexing into a list and there...
1
5349
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 the I dont need filtering in Oracle, but only indexing. If I put file references to the filtered files in the database and index these (using FILE_DATASTORE), everything works fine. But I rather put the filtered data in the database, and index it...
2
8089
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: http://kbalertz.com/954822/install-configure-Indexing-Service-Windows-Server-computer.aspx http://kbalertz.com/820105/Application-Query-Indexing-Service-Catalog-Using-Visual-Basic.aspx I can search some files .xls .doc and others but It will not find anything in .pdf
0
8252
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8372
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8003
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8240
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5410
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3862
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3901
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2387
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.