Skip to Main Content
Blog

Concatenate two Arrays in Python

Concatenate two Arrays in Python

def main():
	"""
	Prints a separated list of even and odd numbers.
	"""

	array = list(map(int, input("Enter array: ").split()))

	evens, odds = split(array)

	print("Evens:", evens)
	print("Odds: ", odds)


def split(array: list[int]):
	"""
	Splits a list into two separate 'even' and 'odd' lists.
	"""

	# Create the even and the odd array
	evns: list[int] = []
	odds: list[int] = []

	# Split the even and odd elements
	for i in array:
		if i % 2 == 0:
			evns.append(i)
		else:
			odds.append(i)

	return evns, odds


if __name__ == "__main__":
	main()
def main():
	"""
	Splits an array into three arrays: negative, positive and zero.
	"""

	array = list(map(int, input("Enter list: ").split(",")))

	pos: list[int] = []
	neg: list[int] = []
	for i in array:
		if i < 0:
			neg.append(i)
		elif i > 0:
			pos.append(i)

	zer = len(array) - (len(pos) + len(neg))

	print("Negatives:", neg)
	print("Positives:", pos)
	print("Zeros:", zer)


if __name__ == "__main__":
	main()