By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,171 Members | 776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,171 IT Pros & Developers. It's quick & easy.

'Spam' and 'Eggs' (the list) [solved]

P: 10
I need to generate a list containing 500 words. Each word should be, 'Spam', unless the index of the word in the list is a multiple of 3 or 5. In which case the word should be, 'eggs'. The index of the first word is 0.

Anyone know where I should start?
Thanks in advance for the help.
Nov 11 '06 #1
Share this Question
Share on Google+
4 Replies


Subsciber123
P: 87
Your question is not clear enough. State an EGGsample of what you want to start with, and what you want to end with.
Nov 11 '06 #2

P: 10
Sorry...I wrote the question exactly as my homework ask it. Maybe thats why I feel lost:

I guess I should have a list ['eggs', 'Spam', 'Spam', 'eggs', 'Sam', 'eggs', 'eggs', 'Spam', 'Spam', 'eggs', 'eggs', 'Spam', 'eggs', 'Spam', 'Spam', 'eggs', 'spam',.......]
but I need to find out how to write that I want the multiples of 3 and 5 to say eggs and all the rest to say Spam.

Hope that is clearer........
Nov 11 '06 #3

Subsciber123
P: 87
Expand|Select|Wrap|Line Numbers
  1. my_list=["spam"]*500
  2. for i in range(500):
  3.     if i%3==0 or i%5==0:
  4.         my_list[i]="eggs"
  5. print my_list
  6.  
That should just about do it.
Nov 11 '06 #4

P: 10
Thank you so much! I have been working on that question for the last 2 hours. Your response works perfect!
I really appreciate the help!!!!
= )
Nov 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.