-2

I have following list

count =('OK', ['3'])

i need to extract number, tried following but only got

[]

2 Answers2

1

You have a tuple with a list nested inside that contains a string '3' so you can format that however you want.

This is verified by:

count =('OK', ['3'])
print(type(count))
for item in count:
    if isinstance(item, int):
        print(item)
    elif isinstance(item, list):
        print(item)

resulting in:

<class 'tuple'>
['3']

To access it as mentioned in comments:

number = int(count[1][0])
eagle33322
  • 228
  • 2
  • 11
1
count =('OK', ['3','2'])
for item in count :
    if type(item) == list :
        item_in_list = [val for val in item ]
print(item_in_list)  

OutPut : ['3','2']

This is what I came up with! You can extract the number in the list if you want and print

Archiac Coder
  • 156
  • 2
  • 13