| | I need to get the lesser n numbers of a list in Python. I need this to be really fast because it's in a critical part for performance and it needs ... | (code examples are python)
Lets assume we have a list of percentages that add up to 100:
mylist = [2.0, 7.0, 12.0, 35.0, 21.0, 23.0]
Some values of mylist may ... | Given [1,2,3,4,5], how can i do something like 1/1, 1/2, 1/3,1/4,1/5, ...., 3/1,3/2,3/3,3/4,3/5,.... 5/1,5/2,5/3,5/4,5/5
I would like to store all the results, find the minimum, and return the two numbers used to ... | I need an algorithm which given a list L and a number N, returns a list of N smaller lists where the sublists are "balanced". Examples:
algo(range(1, 8), 3) -> ...
| Can you make it more simple/elegant?
def zigzag(seq):
"""Return two sequences with alternating elements from `seq`"""
x, y = [], []
p, q ...
| What is the simplest way to create this list in Python?
First, suppose I have this nested list:
oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
I want a function to spit out:
newList = [ ...
| I have data which in theory is a list, but historically has been input by the user as a free form text field. Now I need to separate each item of ... | | I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.1
For example, here ... | There are 2 input lists L and M, for example:
L = ['a', 'ab', 'bba']
M = ['baa', 'aa', 'bb']
How to obtain 2 non-empty output lists ... | I'm trying to find a neat way of summing a list and a list of lists in the same function, so far I've got:
import operator
"""
Fails late for item = ['a', ...
| I have a nested list something like this:
PLACES = (
('CA', 'Canada', (
('AB', 'Alberta'),
...
| Suppose I have a list of lists of elements which are all the same (i'll use ints in this example)
[range(100)[::4], range(100)[::3], range(100)[::2], range(100)[::1]]
What would be a nice and/or efficient way to ... | One of the major strengths of python and a few other (functional) programming languages are the list comprehension. They allow programmers to write complex expressions in 1 line. ... | given a list of purchase events (customer_id,item)
1-hammer
1-screwdriver
1-nails
2-hammer
2-nails
3-screws
3-screwdriver
4-nails
4-screws
i'm trying to build a data structure that tells how many times an item was bought with another item. Not bought at the same time, ... | I'm having some trouble developing an algorithm to determine the minimum of a list of n elements. It's not the case of finding the minimum of an array of length n, ... | i have a huge list of two-element tuples which are coordinates of segments (start, end). In this way in a list below
list = [ (1,4), (2, 3), (10, 20), (18, 45) ...
| I'm working on a Project Euler problem which requires factorization of an integer. I can come up with a list of all of the primes that are the factor of a ... | I have some code that calculates the lowest common multiple for a list of numbers. I would like to modify this code to return a list of values that represents ... | Is there a pythonic way to check if a list is already sorted in AESC or DESC.
listtimestamps=[1,2,3,5,6,7]
something like listtimestamps.isSorted() that returns True or False.
EDIT: I want to input a list of ... | Having two lists, I want to get all the possible couples. (a couple can be only one element from list 1 and another from list 2)
If I do a double "foreach" ... | This question asks how to determine if every element in a list is the same. How would I go about determining if 95% of the elements in a list ... | I'm a Python newbie, I worked with list for 2 months and I have some questions. I have some list and they have duplicate items. I can get duplicate items between ... | I have two list of album names, ordered by some score.
albums_today = ['album1', 'album2', 'album3']
albums_yesterday = ['album2', 'album1', 'album3']
How can I calculate the change of list order and get something like
{'album1':1, ...
| Given two lists of integers, generate the shortest list of pairs where every value in both lists is present. The first of each pair must be a value from the first ... | I'm currently python and quite new to this language.
Sort List Based on Two CriteriaGiven a list of words, return a list with the same words in order of length (longest to ... | I have a list made out of tuples such as the one below:
(2809.3994479562093, 1032.5989696312365, 0.0), {'level': '2', 'id': '1'})
having a sett of different values for the level key in the ... | I'm reading about algorithms in Python but I'm also new in Python.
I just need to understand how this is made:
a, b, c, d, e, f, g, h = range(8)
N = [
[b, ...
| I'm struggling with an algorithm to divide a group of contestants into smaller groups to make up rounds. Take for example a group of 20 people, which I want to divide ... | I have two lists:
eg.
a = [1,8,3,9,4,9,3,8,1,2,3]
and
b = [1,8,1,3,9,4,9,3,8,1,2,3]
Both contain ints. There is no meaning behind the ints (eg. 1 is not 'closer' to 3 than it is to 8).
I'm trying ... | I need an algorithm to split a list of values into such chunks, that sum of values in every chunk is (approximately) equals (its some variation of Knapsack problem, ... | I have posted a bit here related to a project I have been trying to work on and I keep hitting design problems and have to design from scratch. So ... | I have a list-of-list-of-lists, where the first two act as a "matrix", where I can access the third list as
list3 = m[x][y]
and the third list ... | I have a dict containing lists under its keys:
dct = {'a': [1, 2, 3],
'b': [1, 2, 3, 4],
...
| a = [1, 2, 3, 1, 2, 3]
b = [3, 2, 1, 3, 2, 1]
a & b should be considered equal, because they have exactly the same elements, only in different ... | Just for the sake of exercise I'm trying to find a way to express Pascal's Triangle with Python list comprehension, and do that in iterative way. I'm representing Pascal's ... | I have a list like this
[[x,y,1],[w,u,4],[m,n,3] ... [p,q,5]]
I need to sort the outer list by the third (last) element of the inner list, the desired result would be:
[[x,y,1],[m,n,3],[w,u,4] ... [p,q,5]]
What's the ... | Given lists: [1, 5, 6], [2, 3, 5, 6], [2, 5] etc. (not necessarily in any sorted order) such that if x precedes y in one list, then x precedes ... |
|