+ 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.
12 Réponses
+ 5
Here's another way
https://code.sololearn.com/ctM6LvG9UH7i
+ 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
+ 2
+ 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 )
+ 1
Ghassan Al Khoury on what condition do you want to get specific names?
+ 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
+ 1
Thanks everyone for the help. I really appreciate it.
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
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?
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?
0
Ipang no, it should be from the smallest to the biggest lol
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?