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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.