+ 1

How to get some specific items from a list?

I've been trying to solve this problem but I haven't come up with anything that works. So if I have a list like that List1 = [3, 'Mike', 5, 'Matt', 'Dillion', 'April', 9, 'Ramos'] Is there a possible way to output Matt Dillon April Basically, just the strings or names between integers.

30th Mar 2021, 4:13 AM
Ghassan Al Khoury
Ghassan Al Khoury - avatar
12 Respuestas
30th Mar 2021, 5:37 AM
David Ashton
David Ashton - avatar
+ 2
I made it by finding the indices of integer elements and copy elements from <List1> within the range of the second index and the third. https://code.sololearn.com/cazQ0O2iWpfg/?ref=app
30th Mar 2021, 5:35 AM
Ipang
30th Mar 2021, 5:42 AM
Carlos
Carlos - avatar
+ 1
Use type(object) to verify an object's type List1 = [3, "Mike", 5, "Matt", "Dillion", "April", 9, "Ramos"] for item in List1: if type( item ) is str: print( item )
30th Mar 2021, 4:19 AM
Ipang
+ 1
Ghassan Al Khoury on what condition do you want to get specific names?
30th Mar 2021, 4:31 AM
Carlos
Carlos - avatar
+ 1
I need to get the names which are after the second lowest number which is 5 and then stops when it reaches another number which is 9
30th Mar 2021, 4:35 AM
Ghassan Al Khoury
Ghassan Al Khoury - avatar
+ 1
Thanks everyone for the help. I really appreciate it.
30th Mar 2021, 8:10 AM
Ghassan Al Khoury
Ghassan Al Khoury - avatar
0
Ipang I really appreciate your time for responding to my question. However, I know how to do that. I'm not asking to get all of the names. I'm asking to get specific names between ints. The output should be: Matt Dillion April
30th Mar 2021, 4:23 AM
Ghassan Al Khoury
Ghassan Al Khoury - avatar
0
I saw you wrote "Basically, just the strings or names between integers." that's how I interpreted it. Never mind, can you tell me what qualifies a name then?
30th Mar 2021, 4:26 AM
Ipang
0
Oh now I get what you mean by "between the integers" Can the numbers be randomly placed though? I mean, what if 9 comes before 5? is it possible?
30th Mar 2021, 4:42 AM
Ipang
0
Ipang no, it should be from the smallest to the biggest lol
30th Mar 2021, 4:44 AM
Ghassan Al Khoury
Ghassan Al Khoury - avatar
0
Ghassan Al Khoury I might be able to help you, if you could provide a bit more information about how the code should work. For example, say List1 = ["Karen", 5, "Mike", "Matt", 3, 9, "Ramses", 12, 0, "Orb", 0, "Apple"]. What should be the expected output?
30th Mar 2021, 5:10 AM
Calvin Thomas
Calvin Thomas - avatar