In Russia regular bus tickets usually consist of 6 digits. The ticket is called lucky when the sum of the first three digits equals to the sum of the last three digits. Write a function to find out whether the ticket is lucky or not. Return true if so, otherwise return false. Consider that input is always a string. Watch examples below.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def is_lucky(ticket):
	

Solutions:
def is_lucky(ticket):
	if len(ticket) == 6 and ticket.isdigit():
		t = list(map(int, ticket))
		return sum(t[:3]) == sum(t[3:])
	return False


def is_lucky(t):
	return len(t) == 6 and t.isdigit() and (sum(map(int, t[:3])) == sum(map(int, t[3:])))


def is_lucky(ticket):
	return True if len(ticket) == 6 and ticket.isnumeric() and (sum([int(i) for i in ticket[:3]]) == sum([int(i) for i in ticket[3:]])) else False


import re

def is_lucky(ticket):
	return bool(re.match('\\d{6}', ticket)) and sum((int(i) for i in ticket[:3])) == sum((int(i) for i in ticket[3:]))


def is_lucky(ticket):
	try:
		if ticket == '':
			return False
		else:
			idk = [int(x) for x in ticket]
			first = sum(idk[0:3])
			second = sum(idk[3:6])
			if first == second:
				return True
			else:
				return False
	except:
		return False


def is_lucky(ticket):
	return False if len(ticket) != 6 or not ticket.isdigit() else sum(map(int, ticket[:3])) == sum(map(int, ticket[3:]))


def is_lucky(ticket):
	try:
		return sum((int(ticket) // 10 ** i % 10 * complex(0, 1) ** (i // 3 * 2) for i in range(6))) == 0
	except:
		return False


def is_lucky(ticket):
	if len(ticket) != 6:
		return False
	total = 0
	for (i, c) in enumerate(ticket):
		if not c.isdigit():
			return False
		if i < 3:
			total += int(c)
		else:
			total -= int(c)
	return total == 0


def is_lucky(ticket):
	try:
		y = int(ticket)
	except ValueError:
		return False
	return sum([int(x) for x in ticket[0:3]]) == sum([int(x) for x in ticket[3:]])