Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 4th, 2005, 4:10 PM   #1
dezza
Newbie
 
dezza's Avatar
 
Join Date: Mar 2005
Location: Denmark
Posts: 16
Rep Power: 0 dezza is on a distinguished road
Send a message via ICQ to dezza Send a message via MSN to dezza
Count lenght of list inside list, how to print returns

http://ibiblio.org/obp/thinkCS/pytho...h/chap08.htm#3

I'm trying to complete the exercise in this step, can you help me out? ..

I've tried but cannot think of any good methods to do it.

Another thing

How do I get "return" to print when running the code as script? I know that you can see the True and False in the interpreter, but can you make it print the true/false statement when running it as a script (e.g. $ python script.py) ..

I need it in this case:
import string
def isLower2(ch):
  return ch in string.lowercase
__________________
Come in and have a talk!
#programmingforums @ Freenode

Specialities: Linux, XHTML/HTML and CSS.
Learning: Python

Folding@Home Stats

System Requirements: Windows 9x/ME/2000/XP or better
Okay, that makes it run on Linux right?
dezza is offline   Reply With Quote
Old Apr 4th, 2005, 7:13 PM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Using the above example you'd just do a `print isLower2("foo")` or whatever.
Cerulean is offline   Reply With Quote
Old Apr 5th, 2005, 8:21 AM   #3
dezza
Newbie
 
dezza's Avatar
 
Join Date: Mar 2005
Location: Denmark
Posts: 16
Rep Power: 0 dezza is on a distinguished road
Send a message via ICQ to dezza Send a message via MSN to dezza
Thank you Cerulean, anyone who can help me with the excersise?
__________________
Come in and have a talk!
#programmingforums @ Freenode

Specialities: Linux, XHTML/HTML and CSS.
Learning: Python

Folding@Home Stats

System Requirements: Windows 9x/ME/2000/XP or better
Okay, that makes it run on Linux right?
dezza is offline   Reply With Quote
Old Apr 5th, 2005, 10:23 AM   #4
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
I'm pretty sure they want you to take the example and print the length rather than the value ....

horsemen = ["war", "famine", "pestilence", "death"] 

i = 0 
while i < len(horsemen): 
    print len(horsemen[i])
    i = i + 1
sykkn is offline   Reply With Quote
Old Apr 5th, 2005, 11:47 AM   #5
dezza
Newbie
 
dezza's Avatar
 
Join Date: Mar 2005
Location: Denmark
Posts: 16
Rep Power: 0 dezza is on a distinguished road
Send a message via ICQ to dezza Send a message via MSN to dezza
['spam!', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]] ..

Thank you, but this is the previous list, just above the exercise, how could I do the lenght thing on this one? It won't allow me if I use the same code as above with the list content of above ..
__________________
Come in and have a talk!
#programmingforums @ Freenode

Specialities: Linux, XHTML/HTML and CSS.
Learning: Python

Folding@Home Stats

System Requirements: Windows 9x/ME/2000/XP or better
Okay, that makes it run on Linux right?
dezza is offline   Reply With Quote
Old Apr 5th, 2005, 12:16 PM   #6
al1986
Newbie
 
Join Date: Feb 2005
Posts: 24
Rep Power: 0 al1986 is on a distinguished road
If I understand your problem correctly, you can't find the length of each item in the list due to the type of one of the items. Item #2 is an integer, and calling the len function with an integer argument raises a TypeError.

If the nested list was changed to:
['spam!', [1], ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]]

(i.e. replace '1' with a list containing a single item, '1') you could print the length of each element by doing:

for x in l2:
    print len(x)

Hope this helps!
al1986 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC