Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a row from a 2D tuple

This is probably a very straightforward thing but I can't get it.

How do you go about selecting "rows" (I use the word row for lack of a better one) from a 2D (or nD) tuple?

A = [0,1,2,3]
B = [4,5,6,7]
C = (A,B)

I.E., how do I get the result ([1,2],[5,6]) from C?

I've tried C[:][1:2] but I get the result ([4, 5, 6, 7],)

like image 986
jbssm Avatar asked Oct 19 '25 14:10

jbssm


1 Answers

You could use a comprehension:

tuple(x[1:3] for x in C) 
like image 77
John Coleman Avatar answered Oct 21 '25 04:10

John Coleman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!