0

please help me. I have two-dimensional array example :

self.history = [['23295', u'0.0500',  u'0.0700', u'0.0600', u'0.0600'],['23295', u'0.0500', u'0.0700', u'0.0600', u'0.0600']]

i try parsing him and get string but have syntax error, please advice.

for i in  range(int(cac)):
    returning = returning + "\""+str(date_arr[i])+","+ str(self.history[0 for x in range(len(self.history))][i])+"+"

in output i need have somethings like :

"somedate,'23295','23295'" + "somedate,u'0.0500',u'0.0500'" + "somedate,u'0.0700',u'0.0700'"...
2
  • the problem is here: [0 for x in range(len(self.history))] Commented Nov 13, 2014 at 17:43
  • i have in output somethings like that : "2014-11-13 18:44,[0]" Commented Nov 13, 2014 at 17:45

1 Answer 1

1

You have to use two for loops:

for x in range(len(self.history)):
    for i in  range(int(cac)):
        returning = returning + "\""+str(date_arr[i])+","+ str(self.history[x][i])+"+"

Note that your code [x for x in range(len(self.history))] generates a list whereas you need an integer to index your list

Sign up to request clarification or add additional context in comments.

3 Comments

thanks, but as result i have : "2014-11-13 18:45,[0]"2014-11-13 18:46,[0]"2014-11-13 18:47,[0]"2014-11-13 18:48,[0]"2014-11-13 18:49,[0]"2014-11-13 18:50,[0]"2014-11-13 18:51,[0]"2014-11-13 18:52,[0]"...
thanks really for the help, but there is back (example): self.history[0][0], self.history[1][0], self.history[0][1], self.history[1][1], but need in this order : self.history[0][0], self.history[0][1], self.history[0][1], self.history[1][1]... I hope you understand and again thanks
@user3731374 simply change the position of for loops as I edited my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.