473,383 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

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
1 1224
dwblas
626 Expert 512MB
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

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

Similar topics

3
by: Matjaz | last post by:
Dear all, I have run into a problem using python lists and sequence protocol. The first code snippet uses explicit list operations and works fine. PyObject *argseq, *ov; int i, v, len; ...
12
by: Frans Englich | last post by:
Hello, Since Python doesn't have static typing, how is the same result as traditional function overloads results in acheived? With function overloads the "selection of code path depending on...
26
by: A.M | last post by:
Hi, I am new to Python, with C#/Java background Is there any built-in Hash implementation in Python? I am looking for a container that I can access to it's items by name. Something...
1
by: Ben Edwards (lists) | last post by:
I have been going through Dive into Python which up to now has been excellent. I am now working through Chapter 9, XML Processing. I am 9 pages in (p182) in the 'Parsing XML section. The...
9
by: Chris | last post by:
Is anyone aware of any prior work done with searching or matching a pattern over nested Python lists? I have this problem where I have a list like: , 9, 9], 10] and I'd like to search for the...
0
by: Gary Josack | last post by:
Gary Herron wrote: Also os.popen is deprecated. You should probably learn subprocess. Thanks, Gary M. Josack
0
by: twdesign | last post by:
I am a Python newbie! I'm trying to list the feature classes in a dataset (Access .MDB) and then list the fields in each feature class. I'm able to list the feature classes and I'm able to list...
6
by: Eric | last post by:
I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want...
1
by: 4124 | last post by:
how can i cheak if the file empty or not in c language (i have function(FILE* fopenOrDie(char* name);))
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.