How to print 2 horizontal lines - python

I have range of number 132-149
And i have to print 2 horizontal lines
first for even numbers and second for odd numbers
I can print odd and even numbers separately using:
>>> for num in range (132, 150):
if num % 2 == 0:
print (num, end = ' ')
132 134 136 138 140 142 144 146 148
>>> for num in range (132, 150):
if num % 2 != 0:
print (num, end = ' ')
133 135 137 139 141 143 145 147 149
want these two to combine and printe something like this:
132 134 136 138 140 142 144 146 148
133 135 137 139 141 143 145 147 149

Thanks for your edit.
First of all you don't need to iterate over your numbers multiple times. You just can use pythons if/else construct.
even_list = []
odd_list = []
for num in range(132, 150):
if num % 2 == 0:
even_list.append(str(num)) # casted to string to use join function later
else:
odd_list.append(str(num))
print(" ".join(even_list))
print(" ".join(odd_list))
Output
132 134 136 138 140 142 144 146 148
133 135 137 139 141 143 145 147 149

You can do this by appending to 2 different lists:
line1=[]
line2=[]
for num in range (132, 150):
if num % 2 == 0:
line1.append(num)
else:
line2.append(num)
print(line1)
print(line2)

def print_even_odd(start, end):
e_o = []
if start % 2 != 0:
e_o.append(('', start))
for i in range((start + 1) / 2, (end + 1) / 2):
e_o.append((i * 2, i * 2 + 1))
if end % 2 == 0:
e_o.append((end, ''))
for i in e_o:
print("\t%5s\t\t%5s" % i)
for j in [0, 1]:
result = "".join(["%5s" % i[j] for i in e_o])
print(result)
print_even_odd(1, 20)
result is:
1
2 3
4 5
6 7
8 9
10 11
12 13
14 15
16 17
18 19
20
2 4 6 8 10 12 14 16 18 20
1 3 5 7 9 11 13 15 17 19
I hope that, this is what you need

Use:
print '*' * n
where n is the number of asterisks you wish to display.
Here is a more complete example:
lens = [3, 5, 10, 1]
for i, l in enumerate(lens):
print '%02d:%s' % (i + 1, '*' * l)
This displays:
01:***
02:*****
03:**********

Related

Why Pycharm clears the very first lines of the output from the console for long outputs?

I wrote the code below.
the very first line of the resulting output in the Pycharm console is different for the outputs that are not long with those that are long.
I expected that it starts from "1" and scroll more and more for showing more output but it clears the very first lines by itself.
:
code with the output that is not long (note the number "11"):
for x in range(1, 11):
print(str(x), str(x * x), end=' ')
print(str(x * x * x))
the first twelve lines of the console.
the next lines are eliminated due to insignificancy (note it starts from the number "1"):
code with the output that is long (note the number "111111"):
for x in range(1, 111111):
print(str(x), str(x * x), end=' ')
print(str(x * x * x))
the very first line of its console (note it starts from the number "346" instead of "1"):
NOTE:
I know I can see the rest of the results by pressing a key. my question is about the first line of the result, not the last line
That is because the console is only a certain number of lines long (looks like yours is 12) and you are just seeing the last 12 lines. If you scroll up you will see the rest... or you can print in a different way.
for example this:
for x in range(1, 111):
print(str(x), str(x * x), end=' ')
print(str(x * x * x))
# pause every 10 lines
if x % 10 == 0:
input('press a key to continue')
the output:
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
press a key to continue
11 121 1331
12 144 1728
13 169 2197
14 196 2744
15 225 3375
16 256 4096
17 289 4913
18 324 5832
19 361 6859
20 400 8000
press a key to continue
21 441 9261
22 484 10648
23 529 12167
24 576 13824
25 625 15625
26 676 17576
27 729 19683
28 784 21952
29 841 24389
30 900 27000
press a key to continue
31 961 29791
32 1024 32768
33 1089 35937
34 1156 39304
35 1225 42875
36 1296 46656
37 1369 50653
38 1444 54872
39 1521 59319
40 1600 64000
press a key to continue

Print all subsets of an array with sum equal to the target sum

Given an array of N elements find all the subsets of array with sum equal to the target value.
I have seen all the old questions available on this site related to subset sum but none of them worked for me.
Input Format
First line of input contains an Integer N size of array
Second line contains Array elements separated by space
Target sum Value
Output Format
Print all the subarrays(indices of elements).
My Code is working fine for small inputs but it is taking very much time for N >150.
Is there any other efficient algorithm for doing this.
Please tell me how to optimize this code for larger inputs.
And here is my code
from collections import deque
class Pair:
def __init__(self, i, j, path_set):
self.i = i
self.j = j
self.path_set = path_set
def get_subsets(arr, n, value):
"""
This function appends all the possible paths in result list for the given target sum
Arguments:
arr = A list of numbers
n = number of elements in that list arr
value = Target sum for which we want to generate table
"""
# return immediately if there is no possible subset in arr whose sum is equal to value
if dp[n][value] == False:
return
queue = deque()
queue.append(Pair(n, value, set()))
while len(queue) > 0:
pair = queue.popleft()
if pair.i == 0 or pair.j == 0:
result.append(pair.path_set)
else:
exclude = dp[pair.i - 1][pair.j]
if exclude:
queue.append(Pair(pair.i-1, pair.j, pair.path_set))
if pair.j >= arr[pair.i-1]:
include = dp[pair.i - 1][pair.j - arr[pair.i -1]]
if include:
b = pair.path_set.copy()
b.add(pair.i - 1)
queue.append(Pair(pair.i - 1, pair.j-arr[pair.i-1], b))
def make_dp(arr, n, value):
"""
This function makes a table of target sum equal to the value
Arguments:
arr = A list of numbers
n = number of elements in that list arr
value = Target sum for which we want to generate table
Returns:
dp = A 2D boolean table
"""
dp = [[False for i in range(value+1)] for j in range(n+1)]
for i in range(n+1):
for j in range(value+1):
if j ==0:
dp[i][j] = True
elif i == 0:
dp[i][j] = False
else:
if dp[i-1][j]:
dp[i][j] = True
elif j >=arr[i-1]:
if dp[i-1][j-arr[i-1]]:
dp[i][j] = True
return dp
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
value = int(input())
dp = make_dp(arr, n, value)
result = []
get_subsets(arr, n, value)
print(result)
The input for which it is taking very much time:
200
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
200
Please optimize this code or tell me any other approach for doing the same.
Thanks in advance.
You can get this in O(n) time by creating a dictionary of cumulative sums that point to their respective index. When there exists a sum s+T for a sum s in the dictionary, you have a range that adds up to T:
from itertools import accumulate
A = list(range(1,201))
T = 200
sums = {s:i for i,s in enumerate(accumulate(A)) }
result = [ [*range(i+1,sums[s+T]+1)] for s,i in sums.items() if s+T in sums ]
print(result)
# [[4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
# [37, 38, 39, 40, 41],
# [199]]
Even for 1 million values in the list, this takes less than a second.
Note that this assumes that all elements in the array are > 0.
It would possible to support zero and negative values with just a few alterations:
from itertools import accumulate
A = [*range(-10,11)]
T = 20
sums = dict()
for i,s in enumerate(accumulate(A)):
sums.setdefault(s,[]).append(i)
result = []
for cum,starts in sums.items():
if cum+T not in sums: continue
result.extend( [*range(s+1,e+1)] for s in starts
for e in sums[cum+T] if s<e )
print(A)
# [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(result)
# [[9, 10, 11, 12, 13, 14, 15, 16], [12, 13, 14, 15, 16]]
This takes 2-3 seconds on a list with 1 million values but could be longer depending on the size of the result.
You may find that using itertools and combinations is a bit more efficient. The code is also much simpler.
from itertools import chain, combinations
li = [1,2,3,4,5,6]
s=12
itr=chain.from_iterable(combinations(li, n) for n in range(len(li)+1))
result = [el for el in itr if sum(el)==s]
print(result)
Output:
[(1, 5, 6), (2, 4, 6), (3, 4, 5), (1, 2, 3, 6), (1, 2, 4, 5)]
class SubSet_Sum:
def subset_sum(self, arr,target,res=[],temp= []):
if sum(arr)==target:
if not sorted(arr) in res:
res.append(sorted(arr))
else:
for i in range(len(arr)):
temp = arr[:i]+arr[i+1:]
self.subset_sum(temp, target,res)
return res

How to fix the last row of python n generated primelist getting cut off?

last row of n generated primelist gets cut off with odd input
def isPrime(m, L):
while i < n:
if n % i == 0:
return False
i = 1
return True
print()
n = int(input('Enter the number of Primes to compute: '))
primeList = []
x = 2
while len(primeList) < n:
isPrime = True
index = 0
root = int(x ** 0.5) + 1
while index < len(primeList) and primeList[index] <= root:
if x % primeList[index] == 0:
isPrime = False
break
index += 1
if isPrime:
primeList.append(x)
x += 1
print()
n = str(n)
print('The first ' + n + ' primes are: ')
count = 0
tempstring = []
last_row = len(primeList) / 10 + (1 if len(primeList) % 10 else 0)
row = 0
for i in range(0, len(primeList)):
tempstring.append(str(primeList[i]))
count += 1
if count == 10:
print(' '.join(tempstring))
count = 0
tempstring = []
row += 1
elif count == (len(primeList) % 10) and row == (last_row - 1):
print(' '.join(tempstring))
# done
print()
current output:
Enter the number of Primes to compute: 97
The first 97 primes are:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349
353 359 367 373 379 383 389 397 401 409
419 421 431 433 439 443 449 457 461 463
missing the last line: 467 479 487 491 499 503 509
how do I get it to print the last line of primes?
Your code will actually work in python 2 but not in python 3.
In python 2, this line
last_row = len(primeList) / 10 + (1 if len(primeList) % 10 else 0)
will give you 10
but in python 3, it will be 10.7.
Of course, if it is 10.7, your condition elif count == (len(primeList) % 10) and row == (last_row - 1): will not match at all.
To fix it, just do
last_row = int(len(primeList) / 10) + (1 if len(primeList) % 10 else 0)
i.e. make sure the result of len(primeList) / 10 is an integer.
Better still, you should simply divide the numbers in primeList into a list of 10-element list. Then you can do away with these complicated logic. For more details see How do you split a list into evenly sized chunks?

Unsure why program similar to bubble-sort is not working

I have been working on a programming challenge, problem here, which basically states:
Given integer array, you are to iterate through all pairs of neighbor
elements, starting from beginning - and swap members of each pair
where first element is greater than second.
And then return the amount of swaps made and the checksum of the final answer. My program seemingly does both the sorting and the checksum according to how it wants. But my final answer is off for everything but the test input they gave.
So: 1 4 3 2 6 5 -1
Results in the correct output: 3 5242536 with my program.
But something like:
2 96 7439 92999 240 70748 3 842 74 706 4 86 7 463 1871 7963 904 327 6268 20955 92662 278 57 8 5912 724 70916 13 388 1 697 99666 6924 2 100 186 37504 1 27631 59556 33041 87 9 45276 -1
Results in: 39 1291223 when the correct answer is 39 3485793.
Here's what I have at the moment:
# Python 2.7
def check_sum(data):
data = [str(x) for x in str(data)[::]]
numbers = len(data)
result = 0
for number in range(numbers):
result += int(data[number])
result *= 113
result %= 10000007
return(str(result))
def bubble_in_array(data):
numbers = data[:-1]
numbers = [int(x) for x in numbers]
swap_count = 0
for x in range(len(numbers)-1):
if numbers[x] > numbers[x+1]:
temp = numbers[x+1]
numbers[x+1] = numbers[x]
numbers[x] = temp
swap_count += 1
raw_number = int(''.join([str(x) for x in numbers]))
print('%s %s') % (str(swap_count), check_sum(raw_number))
bubble_in_array(raw_input().split())
Does anyone have any idea where I am going wrong?
The issue is with your way of calculating Checksum. It fails when the array has numbers with more than one digit. For example:
2 96 7439 92999 240 70748 3 842 74 706 4 86 7 463 1871 7963 904 327 6268 20955 92662 278 57 8 5912 724 70916 13 388 1 697 99666 6924 2 100 186 37504 1 27631 59556 33041 87 9 45276 -1
You are calculating Checksum for 2967439240707483842747064867463187179639043276268209559266227857859127247091613388169792999692421001863750412763159556330418794527699666
digit by digit while you should calculate the Checksum of [2, 96, 7439, 240, 70748, 3, 842, 74, 706, 4, 86, 7, 463, 1871, 7963, 904, 327, 6268, 20955, 92662, 278, 57, 8, 5912, 724, 70916, 13, 388, 1, 697, 92999, 6924, 2, 100, 186, 37504, 1, 27631, 59556, 33041, 87, 9, 45276, 99666]
The fix:
# Python 2.7
def check_sum(data):
result = 0
for number in data:
result += number
result *= 113
result %= 10000007
return(result)
def bubble_in_array(data):
numbers = [int(x) for x in data[:-1]]
swap_count = 0
for x in xrange(len(numbers)-1):
if numbers[x] > numbers[x+1]:
numbers[x+1], numbers[x] = numbers[x], numbers[x+1]
swap_count += 1
print('%d %d') % (swap_count, check_sum(numbers))
bubble_in_array(raw_input().split())
More notes:
To swap two variables in Python, you dont need to use a temp variable, just use a,b = b,a.
In python 2.X, use xrange instead of range.

Index Error when using python to read BLAST output in csv format

Apologies for the long question, I have been trying to solve this bug but I cant work out what Im doing wrong! I have included an example of the data so you can see what Im working with.
I have data output from a BLAST search as below:
# BLASTN 2.2.29+
# Query: Cryptocephalus androgyne
# Database: SANfive
# Fields: query id subject id % identity alignment length mismatches gap opens q. start q. end s. start s. end evalue bit score
# 7 hits found
Cryptocephalus M00964:19:000000000-A4YV1:1:2110:23842:21326 99.6 250 1 0 125 374 250 1 1.00E-128 457
Cryptocephalus M00964:19:000000000-A4YV1:1:1112:19704:18005 85.37 246 36 0 90 335 246 1 4.00E-68 255
Cryptocephalus M00964:19:000000000-A4YV1:1:2106:14369:15227 77.42 248 50 3 200 444 245 1 3.00E-34 143
Cryptocephalus M00964:19:000000000-A4YV1:1:2102:5533:11928 78.1 137 30 0 3 139 114 250 2.00E-17 87.9
Cryptocephalus M00964:19:000000000-A4YV1:1:1110:28729:12868 81.55 103 19 0 38 140 104 2 6.00E-17 86.1
Cryptocephalus M00964:19:000000000-A4YV1:1:1113:11427:16440 78.74 127 27 0 3 129 124 250 6.00E-17 86.1
Cryptocephalus M00964:19:000000000-A4YV1:1:2110:12170:20594 78.26 115 25 0 3 117 102 216 1.00E-13 75
# BLASTN 2.2.29+
# Query: Cryptocephalus aureolus
# Database: SANfive
# Fields: query id subject id % identity alignment length mismatches gap opens q. start q. end s. start s. end evalue bit score
# 10 hits found
Cryptocephalus M00964:19:000000000-A4YV1:1:2111:20990:19930 97.2 250 7 0 119 368 250 1 1.00E-118 424
Cryptocephalus M00964:19:000000000-A4YV1:1:1105:20676:23942 86.89 206 27 0 5 210 209 4 7.00E-61 231
Cryptocephalus M00964:19:000000000-A4YV1:1:1113:6534:23125 97.74 133 3 0 1 133 133 1 3.00E-60 230
Cryptocephalus M00964:21:000000000-A4WJV:1:2104:11955:19015 89.58 144 15 0 512 655 1 144 2.00E-46 183
Cryptocephalus M00964:21:000000000-A4WJV:1:1109:14814:10240 88.28 128 15 0 83 210 11 138 2.00E-37 154
Cryptocephalus M00964:21:000000000-A4WJV:1:1105:4530:13833 79.81 208 42 0 3 210 211 4 6.00E-37 152
Cryptocephalus M00964:19:000000000-A4YV1:1:2108:13133:14967 98.7 77 1 0 1 77 77 1 2.00E-32 137
Cryptocephalus M00964:19:000000000-A4YV1:1:1109:14328:3682 100 60 0 0 596 655 251 192 1.00E-24 111
Cryptocephalus M00964:19:000000000-A4YV1:1:1105:19070:25181 100 53 0 0 1 53 53 1 8.00E-21 99
Cryptocephalus M00964:19:000000000-A4YV1:1:1109:20848:27419 100 28 0 0 1 28 28 1 6.00E-07 52.8
# BLASTN 2.2.29+
# Query: Cryptocephalus cynarae
# Database: SANfive
# Fields: query id subject id % identity alignment length mismatches gap opens q. start q. end s. start s. end evalue bit score
# 2 hits found
Cryptocephalus M00964:21:000000000-A4WJV:1:2107:12228:15885 90.86 175 16 0 418 592 4 178 5.00E-62 235
Cryptocephalus M00964:21:000000000-A4WJV:1:1110:20463:5044 84.52 168 26 0 110 277 191 24 2.00E-41 167
and I have saved this as a csv, again shown below
# BLASTN 2.2.29+,,,,,,,,,,,
# Query: Cryptocephalus androgyne,,,,,,,,,,,
# Database: SANfive,,,,,,,,,,,
# Fields: query id, subject id, % identity, alignment length, mismatches, gap opens, q. start, q. end, s. start, s. end, evalue, bit score
# 7 hits found,,,,,,,,,,,
Cryptocephalus,M00964:19:000000000-A4YV1:1:2110:23842:21326,99.6,250,1,0,125,374,250,1,1.00E-128,457
Cryptocephalus,M00964:19:000000000-A4YV1:1:1112:19704:18005,85.37,246,36,0,90,335,246,1,4.00E-68,255
Cryptocephalus,M00964:19:000000000-A4YV1:1:2106:14369:15227,77.42,248,50,3,200,444,245,1,3.00E-34,143
Cryptocephalus,M00964:19:000000000-A4YV1:1:2102:5533:11928,78.1,137,30,0,3,139,114,250,2.00E-17,87.9
Cryptocephalus,M00964:19:000000000-A4YV1:1:1110:28729:12868,81.55,103,19,0,38,140,104,2,6.00E-17,86.1
Cryptocephalus,M00964:19:000000000-A4YV1:1:1113:11427:16440,78.74,127,27,0,3,129,124,250,6.00E-17,86.1
Cryptocephalus,M00964:19:000000000-A4YV1:1:2110:12170:20594,78.26,115,25,0,3,117,102,216,1.00E-13,75
# BLASTN 2.2.29+,,,,,,,,,,,
# Query: Cryptocephalus aureolus,,,,,,,,,,,
# Database: SANfive,,,,,,,,,,,
# Fields: query id, subject id, % identity, alignment length, mismatches, gap opens, q. start, q. end, s. start, s. end, evalue, bit score
# 10 hits found,,,,,,,,,,,
Cryptocephalus,M00964:19:000000000-A4YV1:1:2111:20990:19930,97.2,250,7,0,119,368,250,1,1.00E-118,424
Cryptocephalus,M00964:19:000000000-A4YV1:1:1105:20676:23942,86.89,206,27,0,5,210,209,4,7.00E-61,231
Cryptocephalus,M00964:19:000000000-A4YV1:1:1113:6534:23125,97.74,133,3,0,1,133,133,1,3.00E-60,230
Cryptocephalus,M00964:21:000000000-A4WJV:1:2104:11955:19015,89.58,144,15,0,512,655,1,144,2.00E-46,183
Cryptocephalus,M00964:21:000000000-A4WJV:1:1109:14814:10240,88.28,128,15,0,83,210,11,138,2.00E-37,154
Cryptocephalus,M00964:21:000000000-A4WJV:1:1105:4530:13833,79.81,208,42,0,3,210,211,4,6.00E-37,152
Cryptocephalus,M00964:19:000000000-A4YV1:1:2108:13133:14967,98.7,77,1,0,1,77,77,1,2.00E-32,137
Cryptocephalus,M00964:19:000000000-A4YV1:1:1109:14328:3682,100,60,0,0,596,655,251,192,1.00E-24,111
Cryptocephalus,M00964:19:000000000-A4YV1:1:1105:19070:25181,100,53,0,0,1,53,53,1,8.00E-21,99
Cryptocephalus,M00964:19:000000000-A4YV1:1:1109:20848:27419,100,28,0,0,1,28,28,1,6.00E-07,52.8
I have designed a short script that goes through the percentage identity and if it is above a threshold finds the queryID and adds it to a list before removing duplicates from the list.
import csv
from pylab import plot,show
#Making a function to see if a string is a number or not
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
#Importing the CSV file, using sniffer to check the delimiters used
#In the first 1024 bytes
ImportFile = raw_input("What is the name of your import file? ")
csvfile = open(ImportFile, "rU")
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
#Finding species over 98%
Species98 = []
Species95to97 = []
Species90to94 = []
Species85to89 = []
Species80to84 = []
Species75to79 = []
SpeciesBelow74 = []
for line in reader:
if is_number(line[2])== True:
if float(line[2])>=98:
Species98.append(line[0])
elif 97>=float(line[2])>=95:
Species95to97.append(line[0])
elif 94>=float(line[2])>=90:
Species90to94.append(line[0])
elif 89>=float(line[2])>=85:
Species85to89.append(line[0])
elif 84>=float(line[2])>=80:
Species80to84.append(line[0])
elif 79>=float(line[2])>=75:
Species75to79.append(line[0])
elif float(line[2])<=74:
SpeciesBelow74.append(line[0])
def f7(seq):
seen = set()
seen_add = seen.add
return [ x for x in seq if x not in seen and not seen_add(x)]
Species98=f7(Species98)
print len(Species98), "species over 98"
Species95to97=f7(Species95to97) #removing duplicates
search_set = set().union(Species98)
Species95to97 = [x for x in Species95to97 if x not in search_set]
print len(Species95to97), "species between 95-97"
Species90to94=f7(Species90to94)
search_set = set().union(Species98, Species95to97)
Species90to94 = [x for x in Species90to94 if x not in search_set]
print len(Species90to94), "species between 90-94"
Species85to89=f7(Species85to89)
search_set = set().union(Species98, Species95to97, Species90to94)
Species85to89 = [x for x in Species85to89 if x not in search_set]
print len(Species85to89), "species between 85-89"
Species80to84=f7(Species80to84)
search_set = set().union(Species98, Species95to97, Species90to94, Species85to89)
Species80to84 = [x for x in Species80to84 if x not in search_set]
print len(Species80to84), "species between 80-84"
Species75to79=f7(Species75to79)
search_set = set().union(Species98, Species95to97, Species90to94, Species85to89,Species80to84)
Species75to79 = [x for x in Species75to79 if x not in search_set]
print len(Species75to79), "species between 75-79"
SpeciesBelow74=f7(SpeciesBelow74)
search_set = set().union(Species98, Species95to97, Species90to94, Species85to89,Species80to84, Species75to79)
SpeciesBelow74 = [x for x in SpeciesBelow74 if x not in search_set]
print len(SpeciesBelow74), "species below 74"
#Finding species 95-97%
The script works perfectly most of the time but every so often I get the error shown below
File "FindingSpeciesRepresentation.py", line 35, in <module>
if is_number(line[2])== "True":
IndexError: list index out of range
But if I change the script so it prints line[2] it prints all the identities as I would expect. Do you have any idea what could be going wrong? Again apologies for the wall of data.
This has been partly taken from my earlier question: Extracting BLAST output columns in CSV form with python

Categories