logo
down
shadow

Getting indexes of all max values in a list


Getting indexes of all max values in a list

By : miki999
Date : October 18 2020, 06:10 PM
To fix the issue you can do Is there any way in Python to get all indexes of elements which contain max value of a list? , Try this :
code :
l = [1, 3, 2, 2, 1, 1, 1, 2, 3, 2, 1, 1, 1, 3, 1, 1, 3]
mx = max(l)
m = [i for i,j in enumerate(l) if j==mx]
[1, 8, 13, 16]


Share : facebook icon twitter icon
error list indices must be integers, not list. Take values of one array use them as indexes to delete values from anothe

error list indices must be integers, not list. Take values of one array use them as indexes to delete values from anothe


By : Birama DIOP
Date : March 29 2020, 07:55 AM
it helps some times , You are right.
The error is because, in
code :
deleteindex = [val for key,val in dups.iteritems() if seen[key] == '159']
...
print dict(dups.iteritems())  # adding this
deleteindex = [val for key,val in dups.iteritems() if seen[key] == '159']
...
import random

prules = [random.randint(150,156) for i in range(30)]

def get_indexes(li):
    retval = {}
    for i, x in enumerate(li):
        if x not in retval:
            retval[x] = []
        retval[x].append(i)
    return retval               

dups = get_indexes(prules)
indexes = dups.get('156',[])
rulelines = [rulelines[i] for i in range(len(rulelines[:])) if i not in indexes]
dups.get('156',[])
List indexes of duplicate values in a list with Python

List indexes of duplicate values in a list with Python


By : 陳啊哈
Date : March 29 2020, 07:55 AM
Does that help I am trying to modify this definition that lists duplicate items so that it lists indexes of duplicate values. Also, I would like it to list ALL of the duplicates that means the resultant for a = [1,2,3,2,1,5,6,5,5,5] would be duplicate_indexes = [3,4,7,8,9] Here's the definition:
code :
a, seen, result = [1, 2, 3, 2, 1, 5, 6, 5, 5, 5], set(), []
for idx, item in enumerate(a):
    if item not in seen:
        seen.add(item)          # First time seeing the element
    else:
        result.append(idx)      # Already seen, add the index to the result
print result
# [3, 4, 7, 8, 9]
def list_duplicates(seq):
    seen = set()
    seen_add = seen.add
    return [idx for idx,item in enumerate(seq) if item in seen or seen_add(item)]

print list_duplicates([1, 2, 3, 2, 1, 5, 6, 5, 5, 5])
# [3, 4, 7, 8, 9]
Compare two lists' indexes values and write NOT similar values to another list in Python

Compare two lists' indexes values and write NOT similar values to another list in Python


By : VirMa
Date : March 29 2020, 07:55 AM
I wish did fix the issue. That's because for each value in list_two you're adding the value from list_one if it's not equal to the value found at list_two[j][3].
You could adapt your current solution by counting the number of occurrences of each value in list_only_not_similar, and comparing that to the length of list_two. Anything with an equal length is not found in any element.
code :
values_i_want= []
for value in list_two:
    if not value[3] in list_one:
        values_i_want.append(value)
set_one = set(list_one)
values_I_want = [value for value in list_two if list_two[3] not in set_one]
list_not_similar = [x for x in list_two if x[3] not in set_one]
Operation with values at specific indexes in a list of list

Operation with values at specific indexes in a list of list


By : Deandra D'Souza
Date : March 29 2020, 07:55 AM
Any of those help A more pythonic way to do that would be using the sum function along with the for ... in ... generator and do all the work in a single line, like this:
code :
sum1, sum2 = sum(x[1] for x in my_list), sum(x[2] for x in my_list)
Transform List into Map using only two keys and odd or even list indexes as values - Java 8 Stream

Transform List into Map using only two keys and odd or even list indexes as values - Java 8 Stream


By : Kamui
Date : March 29 2020, 07:55 AM
I wish this help you I would like to transform list into map using as key values only two string values. Then as values just list of strings containing elements from odd or even index positions from input list. Here is old fashion code: , You were on the right track with streaming over the indexes:
code :
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;

IntStream.range(0,list.size())
        .boxed()
        .collect(groupingBy(
                i -> i % 2 == 0 ? "even" : "odd", 
                mapping(list::get, toList())
        ));
IntStream.range(0, list.size())
        .boxed()
        .collect(partitioningBy(
                i -> i % 2 == 0, 
                mapping(list::get, toList())
        ));
Related Posts Related Posts :
  • Unit Test Won't Run Tests
  • Use two for loops simultaneously
  • can we display glass bar chart in python with google app engine
  • Scapy install issues. Nothing seems to actually be installed?
  • Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?
  • What does s() mean?
  • ROC AUC value is 0
  • Why is this the value?
  • Best practices for logging in django project
  • Is there a python openid apps-discovery library to get appengine apps onto the apps marketplace
  • Cannot fetch a web site with python urllib.urlopen() or any web browser other than Shiretoko
  • Similar to ``tabnanny``, how can I check that all the python code is using 4 spaces as an indent?
  • Python: object identity question?
  • Multiple For loops, print else only once if condition is not met
  • Select one item from Series and keep the index
  • __repr__ method appears can't be invoked automatically for Exception class
  • Problem with list value (ValueError) in python 3
  • How to get TouchSensor nested under joint in Webots (Python API)
  • How to specify kernel while executing a Jupyter notebook using Papermill's Python client?
  • How to hide password in Database Connection?
  • How to get a list of dictionaries from the following code?
  • 'How to find out noun to which pronoun is referring to' in python
  • Removing a character (^) from each row of panda Dataframe and get unique words in each row
  • Changing a static variable of inherited classes
  • Django Query result comparison with if statement
  • Python: how to merge two dataframe based only on different columns?
  • Filter data by last 3 months and by ID
  • Inplace arithmetic operation versus normal arithmetic operation in PyTorch Tensors
  • How can I add custom signs to spaCy's punctuation functionality?
  • Ensure positive difference of two numbers
  • i keep getting an error that my list index is out of range
  • Is there a way to create gantt charts in python?
  • How to view network weights and bias during training
  • How can I force SAS to wait for a command to fully execute?
  • Remove all occurences of a value from a nested dictionary
  • How to ensure secure randomization for python password generator
  • Amazon SageMaker deploying from model artifacts - what object do we load from archive?
  • [] parameter or input used in sum() function - what is it doing?
  • Outlook email text formatting from Python application
  • Python 3 - comparing enums against hex value
  • Elegant way to check if a float is between two numbers in Python?
  • Understanding return [0,size-1][nums[0]<nums[size-1]] in Python
  • How do I make this script that heats up my CPU safe
  • RegEx for matching capital letters and numbers
  • What is differnces between array[0] and array[0:1] in Python?
  • How to run both items in scrapy function?
  • How to count the number of sequences of n numbers where no two adjacent numbers are the same?
  • Is there a more efficient way to re-write multi if-else statement
  • ValueError: Error when checking target: expected dense_3 to have shape (1000,) but got array with shape (1,)
  • SytanxError: Invalid Sytax
  • Setting debug = False makes the Django app crash with the following error, how to fix it?
  • How to get the average of many lists embedded within each other?
  • Paramiko with subprocess
  • 2D table conversion for example: y = f(x1,x2) => x1 = f(y, x2)
  • Return a literal string of a tuple in python
  • How to split a Column when you have same values?
  • How to perform str.strip in dataframe and save it with inplace=true?
  • why zip(*k) can't work when k is a iterator?
  • How to get list as an input from command line python?
  • Is Tensorflow Dataset.from_generator deprecated in tensorflow 2.0 ? It throws tf.py_func deprecation error
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk