473,507 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return length of string with given index????

10 New Member
This is the exact question given...I wish I could start or make a stab, but I don't know where to begin:

Submit a Python file named, 'countDemo.py', that defines and demonstrates a function that takes a list of strings and an index and returns the length of the string with the given index. If the index is not valid, the function should return a value of -1.

Thank you in advance for any help or insight anyone can give........
Nov 18 '06 #1
3 1400
bartonc
6,596 Recognized Expert Expert
This is the exact question given...I wish I could start or make a stab, but I don't know where to begin:

Submit a Python file named, 'countDemo.py', that defines and demonstrates a function that takes a list of strings and an index and returns the length of the string with the given index. If the index is not valid, the function should return a value of -1.

Thank you in advance for any help or insight anyone can give........
In a file named 'countDemo.py', write something like

Expand|Select|Wrap|Line Numbers
  1. def StringListIndexer(strList, index): 
  2.     if index > len(strList):
  3.         return -1 # Return causes an immediate exit of the function
  4.     return len(strList[index])
  5.  
Then, in the same file you'll want some test code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. aListOfStrs = ['hi', 'hello', 'goodbye']
  3. # remember that the first one is number zero
  4. print StringListIndexer(aListOfStrs, 1)
  5.  
Nov 18 '06 #2
lostbuttrying
10 New Member
ah, ok seeing your example I understand it better.
Thank you...I really appreciate the help!
Nov 19 '06 #3
bartonc
6,596 Recognized Expert Expert
ah, ok seeing your example I understand it better.
Thank you...I really appreciate the help!
Your're welcome. I'm glad to help. Keep posting,
Barton

PS: Have you found the bug yet? There are two clues to where it is.
Nov 19 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2326
by: John Smith | last post by:
Hi, I'm writing a library in C++ which is supposed to be used by people using C. One function I have must return a string to users which is arbitrary length. The user must be able to use this...
5
2923
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; ...
5
2316
by: jen_designs | last post by:
Is there a way to return the character position on a page? Not the x and y coordinates, but the number of characters on a page. For instance i have a html page with the following text: This is my...
7
39827
by: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
12
3766
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
16
4870
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
13
3629
by: coinjo | last post by:
Is there any function to determine the length of an integer string?
2
1921
by: stealth_spoof | last post by:
Hi People wondering if anyone can help me with a problem I'm having I'm trying to create an array with an unspecified length, the length is based on the result i get from another task in the code...
5
1391
by: Eveready | last post by:
I have a webservice that needs to return a paired list, such as created by an arraylist. The problem appears to be in serlizing the xml. Any help on how to return a paired list or arraylist would...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
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,...
0
7376
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...
1
7031
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...
0
7485
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...
0
5623
agi2029
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,...
1
5042
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...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.