Created
September 22, 2022 05:06
-
-
Save im-noob/a402d52a7c21a453ffe2fb5268564d37 to your computer and use it in GitHub Desktop.
Remove string data from nested list and also print index before printing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove string data from nested list and also print index before printing | |
lst=[ | |
[1,2,3], | |
[11,12,'a','b','C','D', 4], | |
[21,'t',23], | |
[4,5,6,['raja','baja', 'saja', 4444]], | |
[7,87,9], | |
'demo', | |
12.5 | |
] | |
def find_str(iter, parent_l, index): | |
if type(iter) == str or type(iter) == int or type(iter) == float: | |
if type(iter) == str: | |
print(f'string {iter} at {index}:', ) | |
parent_l.remove(iter) | |
return iter | |
index = 0 | |
index_d = 0 | |
while index < len(iter): | |
return_val = find_str(iter[index],iter, index_d ) | |
index_d += 1 | |
if type(return_val) != str: | |
index += 1 | |
find_str(lst, None, None) | |
print('********************************************') | |
lst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment