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

Python Lists Help. I have a function that i can not finish

P: 1
How do i start the second part
Expand|Select|Wrap|Line Numbers
  1. def L4(p):
  2.     x=[]
  3.     for i in range (10):
  4.         x.append(randrange(1,7,1))
if
Part 1 The function that takes an input parameter an empty list. It then creates a list 10 elements long, each consisting of a random number between 1 and 6.
Part 2 Using in and slicing,its supposed to check to see if any of the elements occurred twice. If so, use the index function and slicing to check to see if it occurs 3 times in the list. If so, using the index and the slicing, check to see if it occurs 4 times. A variable to keep track of the largest number of occurrences.
Oct 27 '13 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 626
What part do you not understand. It seems pretty straight forward to me. Using "in" to find duplicates, if a number is found a second time, slice off the first part of the list and check the remaining list, and do this until it is not found.
Expand|Select|Wrap|Line Numbers
  1. found = True
  2. while found:
  3.     if num in some_list:
  4.         ## slice, add one to a counter
  5.     else: 
  6.         found = False
  7.  
  8. if ctr > largest_occur:
  9.     largest_occur = ctr 
Oct 27 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.