![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
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? |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Using the above example you'd just do a `print isLower2("foo")` or whatever.
|
|
|
|
|
|
#3 |
|
Newbie
|
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? |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#5 |
|
Newbie
|
['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? |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2005
Posts: 24
Rep Power: 0
![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|