Answer :

Answer:

# the function is defined

# with the list as parameter

def separate_int_and_str(given_list):

# the integer list is initialized as empty list

integer_list = []

# the string list is initialized as empty list

string_list = []

# for-loop goes through the given_list

for each_element in given_list:

# if the element is a type of int, it is attached to integer_list

if (type(each_element) == int):

integer_list.append(each_element)

# if the element is a type of str, it is attached to string_list

elif (type(each_element) == str):

string_list.append(each_element)

# display integer_list

print(integer_list)

# display string_list

print(string_list)

# a call is made to the function testing it with a list parameter

separate_int_and_str([1, 2, 3, 4, 5, 'a', 'd', 'b', 'c'])

Explanation:

A sample image of the output is attached.

${teks-lihat-gambar} ibnahmadbello

Other Questions