473,379 Members | 1,511 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,379 software developers and data experts.

Determine multiple indices within a list

I am trying to return a list of indices for elements within another list that pass some sort of rule (as fast as possible). Currently I am doing:

Elementspassed=[elem for elem in Mylist if point > elem]

for x in Elements passed:
newlist.append(Mylist.index(x))
Mylist[Mylist.index(x)]=[]

I want to incorporate the for loop into the previous line. I am working with extremely large matrices and this current code takes too long. I am interested in the Elementspassed matrix just to be a list of indices in which point>elem rather than the two step process i am taking.

For example:

(for points > 33)
Now: Elementspassed=[34, 35, 34, 52, 51]
newlist=[0, 3, 4, 5, 6]

Want: Elementspassed=[0, 3, 4, 5, 6]
Dec 2 '10 #1

✓ answered by bvdet

Use built-in function enumerate().
Expand|Select|Wrap|Line Numbers
  1. >>> import random
  2. >>> mylist = [random.choice(range(100)) for i in range(10)]
  3. >>> mylist
  4. [76, 28, 54, 8, 99, 29, 23, 33, 62, 0]
  5. >>> [i for i,n in enumerate(mylist) if n > 33]
  6. [0, 2, 4, 8]
  7. >>> 

1 19945
bvdet
2,851 Expert Mod 2GB
Use built-in function enumerate().
Expand|Select|Wrap|Line Numbers
  1. >>> import random
  2. >>> mylist = [random.choice(range(100)) for i in range(10)]
  3. >>> mylist
  4. [76, 28, 54, 8, 99, 29, 23, 33, 62, 0]
  5. >>> [i for i,n in enumerate(mylist) if n > 33]
  6. [0, 2, 4, 8]
  7. >>> 
Dec 2 '10 #2

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

Similar topics

12
by: KinŽsole | last post by:
Hi I'm very new to VB (using VB6) I have two lists one blank and one containing names in the format of surname and then forename.I also have a combo box containing forenames.When I select a...
3
by: chellappa | last post by:
hi i create a c program ,which waas doing operation of linked list.......in single linked list it is working properly, but i want multiple linked list of same member... i am using array of...
2
by: jw56578 | last post by:
Hi, Is there a way to discover all the classes within a given namespace? thanks
6
by: pobnospam | last post by:
I have a field called ingredients where multiple ingredients can be contained in one record (client request). Now when a report is run I need to prompt a user to determine which records to display...
1
by: thomasjbarra | last post by:
I am currenty building up a database for my employee evaluations. As part of the evaluation, there is a written part (summary in memo form) and a quantitative part (number ratings). On my form I...
0
by: Andreas Sheriff | last post by:
Has anyone ever attempted multiple regression within Oracle? Just curious... Thanks, Andreas
5
by: Grubsy4u | last post by:
Hi all, I have recently created a list box in a form.....I wanted to know if there was a way of searching for multiple records within the list box. How can i get this list box to search for...
6
by: John A Grandy | last post by:
InstrumentPropertyEntity string Name InstrumentEntity string Name List<InstrumentPropertyEntityInstrumentProperties For a List<InstrumentEntity, I want to determine the...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.