You were close, you could have done val dataExpanded = data.flatMap { case (s, i, l) => List.range(1, i + 1).map { n => (s, n, l) } } //> dataExpanded : List[(String, Int, List[String])] = List((foo,1,List(a, b)), (bar,1,List(c, d)), (bar,2,List(c, d)), (baz,1,List(e, f))) Or more neatly as val dataExpanded...

python,list,python-2.7,list-manipulation

I would use two simple for loops (it's also generic for LIST being longer than 2): x=[] y=[] for i in range(len(LIST)): for j in LIST[i]: x.append(j[0]) y.append(j[1]) ...

As long as you ensure that the count of the items in a TList does not change, exchanging items is perfectly fine during a for-loop. Note that, depending on the index of the items that are about to be exchanged, some of the items may not be processed or may...

python,python-3.x,list-manipulation

You have to divide by 10, as long as the number is divisible by 10: def remove_zeros(number): while number and number % 10 == 0: number //= 10 return number number_in_a_list = [764996183739035417047009233711337898622621000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] result = [remove_zeros(n) for n in number_in_a_list] ...

(flatten a-list) will do the trick as well. See: http://clojuredocs.org/clojure_core/clojure.core/apply http://clojuredocs.org/clojure_core/clojure.core/concat http://clojuredocs.org/clojure_core/clojure.core/flatten...

m=list(list(a=1,b=2),list(a=1,b=2)) v=1:length(m) varname="c" This will work: m2=lapply(1:length(m), function(i) modifyList(m[[i]],setNames(list(v[[i]]),varname))) or m2=mapply(function(x,y) {x[[varname]] <- y; x},m,v,SIMPLIFY=FALSE) ...

Assuming you want numbered output files, try running a counter inside the loop. #!/bin/bash i=0 while read -r suffix; do let i++ sed "s/$/$suffix/" INPUTFILE.txt >file$i done <SUFFIXFILE.txt Note that sed -i will manipulate the original input file in-place. You don't want that; you want the output in a new...

python,list,dictionary,list-manipulation

Use a dict to index the table. For each row, check if you've already seen the company and do the insertion there. If you need to get more complicated (for instance, same company with different locations) then the index key can become a tuple of the unique information. my_list =...

dynamic,graphics,slider,wolfram-mathematica,list-manipulation

If one slider is moved the other four change proportionally with all summing to 1. v = {0.2, 0.2, 0.2, 0.2, 0.2}; f = Function[{z, k}, {a, b, c, d, e} = v; m = n = o = p = q = 1; Switch[k, 1, a = z; m...

matlab,matrix,replace,list-manipulation

I don't know about your Block function, you don't actually need to convert to a cell matrix but if you do want to then I would do this: A = magic(6); [m,n] = size(A); r=2; %// Desired number rows of blocks, m must be a multiple of r c=2; %//...