list-manipulation Questions

8

Solved

Suppose there are two lists: l1 = [2,2,3] l2 = ['a','b','c'] I wonder how one finds the product of the two such that the output would be: #output: ['a','a','b','b','c','c','c'] if I do: l3 = [] f...
Civic asked 29/7, 2022 at 9:5

14

Solved

I have a list of size < N and I want to pad it up to the size N with a value. Certainly, I can use something like the following, but I feel that there should be something I missed: >>&gt...
Ashburn asked 9/8, 2010 at 9:30

6

Solved

I want to do permutation in Perl. For example I have three arrays: ["big", "tiny", "small"] and then I have ["red", "yellow", "green"] and also ["apple", "pear", "banana"]. How do I get: ["big", ...
Grayback asked 16/3, 2010 at 18:34

7

Solved

What's the most Pythonic efficient way to iterate over a list in sliding pairs? Here's a related example: >>> l ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> for x, y in itertools.izip...
Shrubbery asked 22/10, 2012 at 15:24

13

Solved

I have two lists: big_list = [2, 1, 2, 3, 1, 2, 4] sub_list = [1, 2] I want to remove all sub_list occurrences in big_list. result should be [2, 3, 4] For strings you could use this: '2123124...
Voile asked 25/7, 2018 at 12:13

8

Solved

So suppose we want to produce the list [0, 1, -1, 2, -2, ...in Haskell. What is the most elegant way of accomplishing this? I came up with this solution: solution = [0] ++ foldr (\(a,b) c->a:...
Coffeehouse asked 6/1, 2018 at 17:26

5

Solved

I have a list structure which represents a table being handed to me like this > l = list(list(1, 4), list(2, 5), list(3, 6)) > str(l) List of 3 $ :List of 2 ..$ : num 1 ..$ : num 4 $ :Li...
Servomechanical asked 17/8, 2017 at 11:51

7

Solved

In Python, the only way I can find to concatenate two lists is list.extend, which modifies the first list. Is there any concatenation function that returns its result without modifying its ar...
Difficult asked 3/12, 2010 at 9:16

2

Solved

In other languages (ruby, python, ...) I can use zip(list1, list2) which works like this: If list1 is {1,2,3,4} and list2 is {a,b,c} then zip(list1, list2) would return: {(1,a), (2,b), (3,c), (d,...
Deify asked 11/5, 2010 at 15:4

2

Solved

I'm trying to implement Ravi Sethi's Little Quilt language in Haskell. An overview of Sethi's little quilt can be seen here: http://poj.org/problem?id=3201 Here are the functions that I have so fa...
Cariecaries asked 5/5, 2013 at 20:38

4

Solved

Is there a python builtin that does the same as tupler for a set of lists, or something similar: def tupler(arg1, *args): length = min([len(arg1)]+[len(x) for x in args]) out = [] for i in rang...
Briny asked 13/4, 2011 at 11:56

5

Solved

[3, 3, 3, 4, 4, 2] Would be: [ (3, 3), (4, 2), (2, 1) ] The output should be sorted by highest count first to lowest count. In this case, 3 to 2 to 1.
Dominate asked 25/1, 2011 at 9:6

3

Solved

As part of a bigger problem of enumerating a set, I need to write an OCaml function 'choose' which takes a list and outputs as the list of all possible sequences of size k made up of elements of th...

3

Solved

I know that the map function takes each element of a list (a sequence) and applies a function to it. Recursively (and without respect to termination conditions, etc) map(s, f) = f(s.head) :: map(...
Schacker asked 21/5, 2009 at 5:53
1

© 2022 - 2024 — McMap. All rights reserved.