How to store some elements from a list into another

2017-06-12 Thread José Manuel Suárez Sierra
Hello,
I am stuck with a (perhaps) easy problem, I hope someone can help me:

My problem is:
I have a list of lists like this one:
[[55, 56, 57, 58, 83, 84, 85, 86, 89, 90, 91, 92, 107, 108, 109, 110, 111, 117, 
118, 119, 120, 128, 129, 130, 131, 135, 136, 137, 138, 184, 185, 186, 187, 216, 
217, 218, 219, 232, 233, 234, 235, 236, 237, 238, 267, 268, 269, 270, 272, 273, 
274, 275], [2, 3, 4, 5, 9, 10, 11, 12, 21, 22, 23, 24, 29, 30, 31, 32, 56, 57, 
58, 59, 65, 66, 67, 68, 74, 75, 76, 77, 78, 89, 90, 91, 92, 98, 99, 100, 101, 
102, 125, 126, 127, 128, 131, 132, 133, 134, 135]]

And what I want is to store some of these datum into another list according to 
the next conditions:
1. I just want to store data if these values are consecutive (four in four), 
for instance, for first element I would like to store into the new list: 
[[[55,58],[83,86],[n,n+3]]] and so on.
 I tried something like this:

x=0
y=0
while list6[x][y] == list6[x][y+1]-1 and list6[x][y] == list6[x][y+1]-2 
and list6[x][y] == list6[x][y+1]-3 or list6[x][0]:

list7.append(list6[x][y])
list7.append(list6[x][y+3])
y = y+1
if (list6[x][y])%(list6[x][len(list6[x])-1]) == 0:
x= x+1

if len(list6[x]) == x and len(list6[x][y]) == y:
break


It does not work

I appreciate your help 
Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Doubt with files

2017-02-14 Thread José Manuel Suárez Sierra
hello,
im trying to read a rtf or txt file with this python script:

with open(dirFichero,'r') as reader:
for line in reader:
print line

the problem is that shown is :

{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810

{\fonttbl\f0\fswiss\fcharset0 Helvetica;}

{\colortbl;\red255\green255\blue255;}

{\*\expandedcolortbl;;}

\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0

\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0



\f0\fs24 \cf0 1l2m,1svo,1lme}


INSTEAD of:
1l2m,1svo,1lme

How could I fix it?

THANK YOU
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: doubt loading pages

2017-02-01 Thread José Manuel Suárez Sierra
El miércoles, 1 de febrero de 2017, 11:55:11 (UTC+1), José Manuel Suárez Sierra 
 escribió:
> hello everyone,
> Im trying to make a program that takes an archive from pdb (for instance this 
> link http://www.rcsb.org/pdb/files/fasta.txt?structureIdList=5HXY
> 
> after reading it I want it to save in a list only this part of the archive:
> 
> MGSSHHSSGLVPRGSHMASMTGGQQMGRGSMPAETNEYLSRFVEYMTGERKSRYTIKEYRFLVDQFLSFMNKKPDEITPMDIERYKNFLAVKKRYSKTSQYLAIKAVKLFYKALDLRVPINLTPPKRPSHMPVYLSEDEAKRLIEAASSDTRMYAIVSVLAYTGVRVGELCNLKISDVDLQESIINVRSGKGDKDRIVIMAEECVKALGSYLDLRLSMDTDNDYLFVSNRRVRFDTSTIERMIRDLGKKAGIQKKVTPHVLRHTFATSVLRNGGDIRFIQQILGHASVATTQIYTHLNDSALREMYTQHRPRY
> 
> I have written this:
> 
> import urllib2
> 
> 
> seq=raw_input("Introduce pdb code \n")
> 
> 
> 
> seq = 
> urllib2.urlopen("http://www.rcsb.org/pdb/files/fasta.txt?structureIdList="+seq)
> print seq.read()
> 
> 
> seq.close()
> 
> 
> My question is, how do I save this into a python list?
> 
> Thank you!

What I need is to convert the whole archive into a list, how could I do it?
-- 
https://mail.python.org/mailman/listinfo/python-list


doubt loading pages

2017-02-01 Thread José Manuel Suárez Sierra
hello everyone,
Im trying to make a program that takes an archive from pdb (for instance this 
link http://www.rcsb.org/pdb/files/fasta.txt?structureIdList=5HXY

after reading it I want it to save in a list only this part of the archive:

MGSSHHSSGLVPRGSHMASMTGGQQMGRGSMPAETNEYLSRFVEYMTGERKSRYTIKEYRFLVDQFLSFMNKKPDEITPMDIERYKNFLAVKKRYSKTSQYLAIKAVKLFYKALDLRVPINLTPPKRPSHMPVYLSEDEAKRLIEAASSDTRMYAIVSVLAYTGVRVGELCNLKISDVDLQESIINVRSGKGDKDRIVIMAEECVKALGSYLDLRLSMDTDNDYLFVSNRRVRFDTSTIERMIRDLGKKAGIQKKVTPHVLRHTFATSVLRNGGDIRFIQQILGHASVATTQIYTHLNDSALREMYTQHRPRY

I have written this:

import urllib2


seq=raw_input("Introduce pdb code \n")



seq = 
urllib2.urlopen("http://www.rcsb.org/pdb/files/fasta.txt?structureIdList="+seq)
print seq.read()


seq.close()


My question is, how do I save this into a python list?

Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Doubt with matrix

2017-01-12 Thread José Manuel Suárez Sierra
Hello, I want to  go over matrix indexs with this code:
def comparador2(a, b):
c3 = ["0"]  # variables
x = -1  # contador de letras aniadidas a c3
i = 0  # contador bucle secuencia a
j = 0  # contador bucle secuencia b
l1 = len(a)
l2 = len(b)
cont = []  # contador de ciclos poner primer termino a 0
k = -1  # contador de 0 y 1 aniadidos a cont

if l1 > l2:  # metodo de la burbuja que elige la secuencia mas larga 
REVISAR puede ser alreves
aux = a
a = b
b = aux

for a[i] in a:  # en la secuencia1 recorro los elementos

for b[j] in b :

if a[i] == b[j] and i <= l1 and j <= l2:  # Si el elemento i de 
la seq1 es igual que el elemento j de la seq2, y el numero de elementos en i y 
j es menor o igual que la longitud de las secuencias 1 y 2
c3.append(a[i])  # se aniade el elemento comun a la lista c3
x = x + 1
k = k + 1
j = j + 1  # se pasa el elemento siguiente de la seq2
i = i + 1  # se pasa el elemento siguiente de la seq1
cont.append(1)



elif a[i] != b[
j] and i <= l1 and j <= l2:  # si no coinciden estos 
elementos se pasa al siguiente elemento de la lista 2
j = j + 1
k = k + 1
cont.append(0)
if cont[k] == 0 and cont[k - 1] == 1 and cont[k - 2] == 0 
and k >= 2:
i = i - 1
j = j - 1
else:
k = k + 1
cont.append(0)
if i == l2:
i = i + 1
j = 0


return c3

and this issue is prompted:
IndexError: list assignment index out of range

How could I fix it?

Thank you for your assistance
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with this code

2017-01-09 Thread José Manuel Suárez Sierra
El lunes, 9 de enero de 2017, 14:09:09 (UTC+1), José Manuel Suárez Sierra  
escribió:
> Hello, I am trying to make a code wich compares between 2 or several 
> sequences (lists). It compares every element in a list with another list 
> elements. For example, if we have a list_a=["a","b","c","d"] and 
> list_b=["a","b"] I want to obtain a new list_c containing elements that match 
> between these lists (a and b here), but, if for instance list_b were 
> ["a","c"] the program must not store this data because they are not in same 
> order.
> 
> Said this, I wrote this code but it doesnt work:
> 
> if __name__ == "__main__":
> 
> 
> def compare(a, b):
> 
> i = 0
> j = 0
> c1 = []
> 
> while a[i] == b[j]:
> c1.append(a[i])
> j = j+1
> i=i+1
> 
> return c1
> 
> 
> 
> 
> cadena_1=raw_input("Introduce list 1 \n")
> cadena_2 = raw_input("Introduce list 2 \n")
> 
> 
> transf1=list(cad_1) 
> transf2 = list(cad_2)
> 
> 
> print compare(transf1,transf2)
> 
> 
> 
> 
> Thank you

Thank you!

Here is my code, I dont understand why it doesnt work very well:
if __name__ == "__main__":


cadena_1 = raw_input("Introduce la cadena 1 \n")
cadena_2 = raw_input("Introduce la cadena 2 \n")
# n=input("De cuantas letras quieres hacer la comparacion?\n")

transf1 = list(cadena_1)  
transf2 = list(cadena_2)
l1=len(transf1)
l2=len(transf2)
c3=[]
i=0
j=0


for transf1[i] in transf1:  
for transf2[j] in transf2:   
if transf1[i]==transf2[j]: 
c3.append(transf1[i])   
i=i+1   
j=j+1   
else:  
j=j+1   

print c3

This is the traceback:
line 18, in 
   for transf2[j] in transf2:
IndexError: list assignment index out of range

If I have initialized j=0 (such as i) why does it not work?
I want the script to read sequence 1 and compares every element inside it with 
elements in sequence 2 no mattering where it matches.

Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with this code

2017-01-09 Thread José Manuel Suárez Sierra
El lunes, 9 de enero de 2017, 14:09:09 (UTC+1), José Manuel Suárez Sierra  
escribió:
> Hello, I am trying to make a code wich compares between 2 or several 
> sequences (lists). It compares every element in a list with another list 
> elements. For example, if we have a list_a=["a","b","c","d"] and 
> list_b=["a","b"] I want to obtain a new list_c containing elements that match 
> between these lists (a and b here), but, if for instance list_b were 
> ["a","c"] the program must not store this data because they are not in same 
> order.
> 
> Said this, I wrote this code but it doesnt work:
> 
> if __name__ == "__main__":
> 
> 
> def compare(a, b):
> 
> i = 0
> j = 0
> c1 = []
> 
> while a[i] == b[j]:
> c1.append(a[i])
> j = j+1
> i=i+1
> 
> return c1
> 
> 
> 
> 
> cadena_1=raw_input("Introduce list 1 \n")
> cadena_2 = raw_input("Introduce list 2 \n")
> 
> 
> transf1=list(cad_1) 
> transf2 = list(cad_2)
> 
> 
> print compare(transf1,transf2)
> 
> 
> 
> 
> Thank you

Thanks for your reply,
I wrote this code:
def comparar(cad1, cad2):
i = 0
j = 0
cad3 = []
k = True

for cad1[i] in cad1:
k = True
for cad2[j] in cad2:
while cad1[i] == cad2[j] and i<= len(cad1) and j <= len(cad2):
cad3.append(cad1[i])
i = i + 1
j = j + 1

if cad1[i] != cad2[j]:
k = False
i = i + 1
return cad3

This is a function, another important thing is the order of elements, it must 
be ordered as it appears in one of the lists, in your example, my function must 
return a list with elements 1,2,5 in that order.

I cant find my mistake in these function I wrote you above.

Thank you very much
-- 
https://mail.python.org/mailman/listinfo/python-list


Help with this code

2017-01-09 Thread José Manuel Suárez Sierra
Hello, I am trying to make a code wich compares between 2 or several sequences 
(lists). It compares every element in a list with another list elements. For 
example, if we have a list_a=["a","b","c","d"] and list_b=["a","b"] I want to 
obtain a new list_c containing elements that match between these lists (a and b 
here), but, if for instance list_b were ["a","c"] the program must not store 
this data because they are not in same order.

Said this, I wrote this code but it doesnt work:

if __name__ == "__main__":


def compare(a, b):

i = 0
j = 0
c1 = []

while a[i] == b[j]:
c1.append(a[i])
j = j+1
i=i+1

return c1




cadena_1=raw_input("Introduce list 1 \n")
cadena_2 = raw_input("Introduce list 2 \n")


transf1=list(cad_1) 
transf2 = list(cad_2)


print compare(transf1,transf2)




Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list