Dear group,
I am frustrated to ask some questions on topics that I
thought covered well. my logic is not correct.
I have a simple list:
>>> a
['a', 'apple', 'b', 'boy', 'c', 'cat']
I want to create a dictionary:
dict = {'a':'apple',
'b':'boy',
'c':'cat'}
my way of doing this :
>>> keys = [] # create a list of all keys i.e a,b,c)
>>> vals = [] # create a list of all values i.e
#appele,boy,cat etc.
>>> dict = {}
>>> dict = zip(keys,vals)
Problem:
How do i capture every alternative element in list a:
I am unable to pump the a,b, and c into keys list
and apple, boy,cat into vals list.
Trial 1:
>>> while i >= len(a):
print a[i]
i = i+2 -- I thought i+2 will give me alternative
elements
Trial 2:
>>> for index,i in enumerate(range(len(a))):
print a[i]
print a[index+1]
a
apple
apple
b
b
boy
boy
c
c
cat
cat
Please help me. It is also time for me to refer my
prev. notes :-(
thanks
K
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor