Home > Mobile >  Find the first number is tuple in python
Find the first number is tuple in python

Time:06-04

I have this code and this a,b and c values and after appeidnig in tuple i need to find the first number of 1 and last value from 7 ,how i can get this two first and last value from the tuple.

a=1,5
b=4,7
c=['a']
r=[]
for i in  (a,b,c):
  if i not in r:
     r.append(i)

i tried this way but it is just giving me

r[0]=(1, 5) and r[1]=(4,7)

i am expecting to get 1, and 7 value, how i can get the first value from a and last value of b

CodePudding user response:

If its always the first and last one you can work with indexes/slicing.

r = [a[0],b[-1]]

Index 0 gives the first element and -1 gives the last.

Hope it helps!

a=1,5
b=4,7
c=['a']
r = [a[0],b[-1]]
print(r)
  • Related