#### Category : itertools

For a given substring, I need to determine all the lengths, in order, of the repeating chains of that substring in a given string. Example: for the substring ATT and a string ATTATTATT GGG ATTATT GGG ATT, I want to return (3,2,1). I think I have a solution, but it’s inelegant and potentially slow (written ..

My code is: import itertools a = [*range(22)], [*range(22)], [*range(22)], [*range(22)] combination = [seq for seq in itertools.product(*a) if sum(seq) <= 21] print(combination) lst1 = [item[0] for item in combination] lst2 = [item[1] for item in combination] lst3 = [item[2] for item in combination] lst4 = [item[3] for item in combination] My result is: "[….., ..

i used itertools.combinations to list all possible combinations of a list…but how do i pick only the neighbors so that the users are all together list =[1,2,3,4,5,6,7,8,9,10,11,12] occupied = [2,6,7,11] remaining seats are available… Now how do i arrange two folks together always in the available seats.. 1 0 3 4 5 0 0 8 ..

Given two lists X and Y: X = [‘A’, ‘B’, ‘C’, ‘D’] Y = [‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’] How to create all the possible sets of 4 combinations with the restriction of considering at least 2 elements of X and Y. For example, a valid combination would look like this: [(‘A’, ‘J’, ‘M’, ..

I’m using Python 3 to solve a problem, but the best I can do single threaded will, at worst case, take up to a year to finish. The price of running it on a 64 core machine on AWS is not prohibitive, however, and I estimate that brings the problem down from about a year ..

Consider the file eclip_bam_paths.txt: /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample1Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample2Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample3Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample4Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample5Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample6Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample7Aligned.sortedByCoord.out.bam /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample8Aligned.sortedByCoord.out.bam and the file eclip_bais_paths.txt: /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample1Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample2Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample3Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample4Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample5Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample6Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample7Aligned.sortedByCoord.out.bai /groups/cgsd/alexandre/eclip/bam_inputs_akshay/10249_sample8Aligned.sortedByCoord.out.bai This code loops through both files but does not retrieve the next value in the loop: keys = [‘bam_rep_1′,’bai_rep_1′,’bam_rep_2′,’bai_rep_2’] l = [] with open(‘src/eclip_bam_paths.txt’) as bams, open(‘src/eclip_bais_paths.txt’) as bais: for bamline,bailine ..

from itertools import product a = [1, 2, 3] dict1 = {"x": 1, "y": 2, "z": 3} dict2 = {"r": 4, "s": 5, "t": 6} for i in product(a, dict1, dict2): print(i) and I got: (1, ‘x’, ‘r’) (1, ‘x’, ‘s’) (1, ‘x’, ‘t’) (1, ‘y’, ‘r’) (1, ‘y’, ‘s’) (1, ‘y’, ‘t’) (1, ‘z’, ..