[Tutor] requesting a help
Matthew Wood
woodm1979 at gmail.com
Mon May 24 07:10:05 CEST 2010
I'd start with something like this:
final_result = []
for data, target in zip(f, t):
a, b = [elem.strip() for elem in line.split()]
c = target.strip()
final_result.append([[a, b], [c]])
Though I'm not sure why you have the "result" data in single element lists.
--
I enjoy haiku
but sometimes they don't make sense;
refrigerator?
On Sun, May 23, 2010 at 10:34 PM, Ahmed AL-Masri <ahmedn82 at hotmail.com>wrote:
>
> I am facing the same problem that little complicated.
> I have this kind of data in a file and actually it's coming from another
> class and it's in form
> ex:
> 0 0
> 0 1
> 1 0
> 1 1
> and another data which it's in form :
> 0
> 1
> 1
> 0
> so now what I need to put it in form
> data= [[[0,0],[0]],
> [[0,1],[1]],
> [[1,0],[1]],
> [[1,1],[0]]
> ]
>
> that is the form for a class that I can use the [0,1] is the inputs and
> inputs[0] is = 0 and inputs[1] is = to 1 . the same thing to the output[0]
> is = 0 and so on
> ok, now this is the problem
> I have successes to to that reading from file in form
> 0 0
> 0 1
> 1 0
> 1 1
> the output
> 0
> 1
> 1
> 0
> and I write it in a file called it data in the new form which is exactly
> what I want in form
> [[[0,0],[0]],
> [[0,1],[1]],
> [[1,0],[1]],
> [[1,1],[0]],]
> but I got a problem. I cannot use this as a data when I read it from the
> data file cuz it's string and I tried to use int but couldn`t solve it yet.
> wish you can help me to find the solution in this problem
> ether I can read the data from the original file and deal with
> it separately or write it to file and read it again which I am trying to do
>
> f=open('data.txt')
> t=open('target.txt')
> n=file('newdata.txt','w')
>
> def arange (inputs, targets, outputfile):
> casesNo = len (inputs.readline())
>
> for s in range (casesNo):
> for line in inputs:
> data=line.rsplit()
> i=','.join(data)
> break
> for line1 in targets:
> data1=line1.rsplit()
> #print data1[0]
> u=','.join(data1)
> z= str(i)
> w= str(u)
> outputfile.write('[[%s],' % (z)+ '[%s]], \n' %(w))
> break
> outputfile.close()
>
> arange(f,t,n) # f : input data, t: target data, n: outputfile
> looking to hearing from you as soon as,
> once again thanks for your help and cooperation,
>
> Regards,
>
>
>
> ------------------------------
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up
> now. <https://signup.live.com/signup.aspx?id=60969>
>
> ------------------------------
> Hotmail: Powerful Free email with security by Microsoft. Get it now.<https://signup.live.com/signup.aspx?id=60969>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100523/fef64712/attachment.html>
More information about the Tutor
mailing list