1
listname = ['bartian', 'lenana', 'kilimanjaro', 'uhuru', 'elgon', 'everest']

while True:    
if listname[:-1] == everest:
print(listname[:-1]+=)

I need a way to loop over this list and print the items in the list. I dont know whether this is pythonic since am having trouble printing the items. I want it to print from the last to first, middle item to lst or to first.

2
Contributors
1
Reply
34
Views
3 Years
Discussion Span
Last Post by Lucaci Andrew
2

Here are some basic list examples:

l = ["1","2","3","4","5","6"]
half = len(l)/2

print (l)                        #normal list
print (l[ : : -1])               #reverse list

print (l[: half - 1 : -1])       #reverse list from last to middle
print (l[half - 1 : : -1])       #reverse list from the middle to first

print (l[ : half : ])            #normal list from first to middle
print (l[half : : ])             #normal list from middle to last

for i in l: print (i)            #print all items from list, each one on its own line

for i in l: print (i),           #print all items from list in a single line

It should generate this output:

'''
['1', '2', '3', '4', '5', '6']
['6', '5', '4', '3', '2', '1']
['6', '5', '4']
['3', '2', '1']
['1', '2', '3']
['4', '5', '6']
1
2
3
4
5
6
1 2 3 4 5 6
'''

Also, you can find more about lists here: Click Here, Click Here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.