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........
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 -
def StringListIndexer(strList, index):
-
if index > len(strList):
-
return -1 # Return causes an immediate exit of the function
-
return len(strList[index])
-
Then, in the same file you'll want some test code: -
-
aListOfStrs = ['hi', 'hello', 'goodbye']
-
# remember that the first one is number zero
-
print StringListIndexer(aListOfStrs, 1)
-
ah, ok seeing your example I understand it better.
Thank you...I really appreciate the help!
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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];
...
|
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...
|
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);
|
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.
...
| |
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...
|
by: coinjo |
last post by:
Is there any function to determine the length of an integer string?
|
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...
|
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...
|
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...
|
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,...
| |
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: 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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |