Given a sequence of items and a specific item in that sequence, return the item immediately following the item specified. If the item occurs more than once in a sequence, return the item after the first occurence. This should work for a sequence of any type.

When the item isn't present or nothing follows it, the function should return nil in Clojure and Elixir, Nothing in Haskell, undefined in JavaScript, None in Python.

```python
next_item([1, 2, 3, 4, 5, 6, 7], 3) # => 4
next_item(['Joe', 'Bob', 'Sally'], 'Bob') # => "Sally"
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def next_item(xs, item):
	

Solutions:
def next_item(xs, item):
	it = iter(xs)
	for x in it:
		if x == item:
			break
	return next(it, None)


import itertools

def next_item(xs, item):
	try:
		xs = iter(xs)
		for x in xs:
			if x == item:
				return next(xs)
	except:
		return None


def next_item(xs, item):
	ret = False
	for x in xs:
		if ret:
			return x
		if item == x:
			ret = True


def next_item(xs, item):
	found = None
	for x in xs:
		if found:
			return x
		if x == item:
			found = True
	return None


def next_item(xs, item):
	it = iter(xs)
	try:
		while True:
			x = next(it)
			if x == item:
				x = next(it)
				return x
	except StopIteration:
		return None


def next_item(xs, item):
	if xs.__class__.__name__ == 'listiterator':
		while xs:
			try:
				if next(xs) == item:
					return next(xs)
			except:
				return
	elif xs.__class__.__name__ == 'count':
		return item + 1
	try:
		return xs[xs.index(item) + 1]
	except:
		return


def next_item(xs, item):
	cursor = iter(xs)
	while True:
		try:
			element = next(cursor)
			if element == item:
				return next(cursor)
		except StopIteration:
			return


def next_item(xs, item, trap=None):
	for i in xs:
		if trap:
			return i
		if i == item:
			trap = True


def next_item(xs, item):
	items = iter(xs)
	for thing in items:
		try:
			if thing == item:
				return next(items)
		except StopIteration:
			return None
	return None


def next_item(xs, item):
	iterXS = iter(xs)
	for i in iterXS:
		if i == item:
			try:
				return next(iterXS)
			except:
				return None


def next_item(xs, item):
	return (lambda x: next(x, None) if item in x else None)(iter(xs))


def next_item(xs, item):
	ret = False
	for j in xs:
		if ret:
			return j
		if j == item:
			ret = True


def next_item(xs, item):
	itemFound = False
	for i in xs:
		if itemFound:
			return i
		if i == item:
			itemFound = True


from itertools import dropwhile, islice

def next_item(xs, item):
	return next(islice(dropwhile(lambda x: x != item, xs), 1, 2), None)


def next_item(xs, item):
	xs = iter(xs)
	if item in xs:
		return next(xs, None)


def next_item(xs, item):
	l = []
	for i in xs:
		l.append(i)
		if item in l and len(l) == l.index(item) + 2:
			break
	return None if item not in l or l[-1] == item else l[l.index(item) + 1]


def next_item(xs, item):
	f = int(1)
	for x in xs:
		if f == 0:
			f = 1
			return x
		if x == item:
			f = 0


def next_item(xs, item):
	flag = False
	for el in xs:
		if flag:
			return el
		if el == item:
			flag = True


def next_item(xs, item):
	flag = False
	for element in xs:
		if flag:
			return element
		if element == item:
			flag = True
	return None


def next_item(xs, item):
	found = False
	for i in xs:
		if found:
			return i
			break
		elif i == item:
			found = True


def next_item(xs, item):
	xl = (i for i in xs)
	try:
		while next(xl) != item:
			continue
		return next(xl)
	except StopIteration:
		pass


def next_item(xs, item):
	it = iter(xs)
	next(iter((el for el in it if el == item)), None)
	return next(it, None)


def next_item(xs, item):
	object = iter(xs)
	for el in object:
		if el == item:
			break
	return next(object, None)


def next_item(xs, item):
	stop = False
	for el in xs:
		if stop:
			return el
		elif el == item:
			stop = True


def next_item(xs, item):
	count = 0
	result = 0
	try:
		if item in xs and xs.index(item) != len(xs) - 1:
			return xs[xs.index(item) + 1]
		else:
			return None
	except:
		try:
			while count != item:
				result = next(xs)
				count += 1
			return result // 2 + 1
		except:
			return 663


def next_item(xs, item):
	done = False
	for i in xs:
		if done == True:
			return i
		if i == item:
			done = True
	return None


def next_item(xs, item):
	end = False
	for i in xs:
		if end:
			return i
		if i == item:
			end = True


def next_item(xs, item):
	found = False
	for x in xs:
		if x == item:
			found = True
		elif found:
			return x
	return


def next_item(xs, item):
	after = False
	for i in xs:
		if after:
			return i
		if i == item:
			after = True


def next_item(xs, item):
	iter_obj = iter(xs)
	while True:
		try:
			element = next(iter_obj)
			if element == item:
				element = next(iter_obj)
				return element
		except StopIteration:
			break
			return None


def next_item(xs, item):
	f = False
	for i in xs:
		if f:
			return i
		if i == item:
			f = True


def next_item(xs, item):
	xs = xs.__iter__()
	while True:
		try:
			if next(xs) == item:
				return next(xs)
		except:
			break


def next_item(xs, item):
	found = False
	for e in xs:
		if found:
			return e
		if e == item:
			found = True
	return None


def next_item(my_list, item):
	found = None
	for x in my_list:
		if found:
			return x
		if x == item:
			found = True
	return None


def next_item(xs, item):
	idx = None
	cnt = 0
	for (i, e) in enumerate(xs):
		if cnt == 1:
			break
		if e == item:
			idx = i
			cnt += 1
	if idx == i:
		return None
	try:
		print(xs[idx])
		return xs[i]
	except:
		if idx is None:
			return idx
		return e


def next_item(xs, item):
	xs = iter(xs)
	for element in xs:
		if element == item:
			try:
				return next(xs)
			except:
				pass


import itertools

def next_item(xs, item):
	if type(xs) == list or type(xs) == tuple or type(xs) == str:
		try:
			return xs[xs.index(item) + 1]
		except:
			return None
	for i in xs:
		if item == i:
			return next(xs)


def next_item(xs, item):
	it = iter(xs)
	try:
		while next(it) != item:
			pass
		return next(it)
	except:
		return None


def next_item(seq, item):
	if type(seq) in [list, str]:
		return seq[seq.index(item) + 1] if (item != seq[-1]) + (item in seq) == 2 else None
	else:
		bar = next(seq)
		foo = next(seq)
		foobar = item + (foo - bar)
		last_item = 0
		for i in range(700):
			try:
				c = seq.__next__()
				if c is not None:
					last_item = c
			except StopIteration:
				break
		return foobar if foobar < last_item else None


def next_item(xs, item):
	iterator = iter(xs)
	for i in iterator:
		if i == item:
			return next(iterator, None)
	return None


import itertools

def nth(iterable, n, default=None):
	return next(itertools.islice(iterable, n, None), default)

def next_item(xs, item):
	a = itertools.dropwhile(lambda x: x != item, xs)
	return nth(a, 1, None)


def next_item(xs, item):
	found = False
	for i in xs:
		if found:
			return i
		if i == item:
			found = True
	else:
		return None


def next_item(xs, item):
	i = None
	for (count, element) in enumerate(xs):
		if element == item:
			i = count + 1
			continue
		if i is not None:
			return element
	return None


def next_item(xs, item):
	i = iter(xs)
	try:
		while next(i) != item:
			pass
		return next(i)
	except StopIteration:
		return None


def next_item(a, item):
	found = 0
	for e in a:
		if found:
			return e
		if e == item:
			found = 1


def next_item(xs, item):
	c = 0
	s = 0
	try:
		return xs[xs.index(item) + 1]
	except (ValueError, IndexError):
		return None
	except AttributeError:
		while True:
			try:
				t = next(xs)
				print(t)
				if c == 1:
					s = t
					break
				if t == item:
					c = 1
			except StopIteration:
				return None
		return s


def next_item(xs, item):
	return_next = False
	for elem in xs:
		if return_next:
			return elem
		elif elem == item:
			return_next = True
	return None


def next_item(l, item):
	try:
		return l[l.index(item) + 1] if item in l and l.index(item) + 1 < len(l) else None
	except:
		return next(l)


def next_item(xs, item):
	flag = False
	for x in xs:
		if flag == True:
			return x
		if item == x:
			flag = True


def next_item(xs, item):
	find = False
	findValue = None
	for i in xs:
		if find:
			findValue = i
			break
		if i == item:
			find = True
	return findValue


def next_item(xs, item):
	c = 0
	l = []
	for x in iter(xs):
		if x == item:
			l.append(x)
			c += 1
		elif c == 1:
			l.append(x)
			break
	try:
		return l[-1] if len(l) >= 2 else None
	except:
		return None


def next_item(r, v):
	ix = iter(r)
	try:
		while next(ix) != v:
			continue
		return next(ix)
	except StopIteration:
		return None


def next_item(xs, item):
	a = iter(xs)
	while True:
		try:
			if next(a) == item:
				return next(a)
		except:
			return None


def next_item(xs, item):
	if hasattr(xs, '__iter__') and hasattr(xs, '__next__'):
		for x in xs:
			if x == item:
				return next(xs)
	if xs == [] or item not in xs:
		return None
	if xs.index(item) == len(xs) - 1:
		return None
	return xs[xs.index(item) + 1]


def next_item(xs, item=None):
	try:
		a = xs.index(item)
		return xs[a + 1]
	except ValueError:
		return None
	except IndexError:
		pass
	except AttributeError:
		if item in xs:
			return next(xs)


def next_item(xs, item):
	xs = iter(xs)
	try:
		while True:
			elem = next(xs)
			if elem == item:
				break
	except StopIteration:
		return None
	try:
		return next(xs)
	except StopIteration:
		return None


import sys

def next_item(xs, item):
	f = 0
	try:
		for i in xs:
			if f == 1:
				return i
			if i == item:
				f = 1
	except:
		pass


import collections

def next_item(xs, item):
	try:
		return xs[xs.index(item) + 1]
	except AttributeError:
		try:
			while next(xs) != item:
				continue
			return next(xs)
		except StopIteration:
			return None
	except (ValueError, IndexError):
		return None


def next_item(xs, item):
	n = False
	for x in xs:
		if n:
			return x
		if x == item:
			n = True


import itertools

def next_item(xs, item):
	next_item = None
	if type(xs) is itertools.count:
		for i in xs:
			if i == item:
				next_item = next(xs)
				break
	else:
		list_xs = list(xs)
		for (n, x) in enumerate(list_xs):
			if item == list_xs[n] and n < len(list_xs) - 1:
				next_item = list_xs[n + 1]
				break
	return next_item


def next_item(xs, item):
	r = False
	for i in xs:
		if r:
			return i
		elif i == item:
			r = True
	return None


def next_item(xs, item):
	y = False
	for x in xs:
		if y:
			return x
		if item == x:
			y = True


def next_item(xs, item):
	itr = iter(xs)
	for elem in itr:
		if elem == item:
			break
	return next(itr, None)


def next_item(xs, item):
	p = 0
	for k in xs:
		if p == 1:
			return k
		if k == item:
			p = 1
	return None


def next_item(xs, item):
	token = 0
	for i in xs:
		if token == 1:
			return i
		if i == item:
			token = 1
	return None


def next_item(xs, item):
	print((xs, item))
	print(type(xs))
	if type(xs) == str:
		print(xs[-2:-1])
		return xs[xs.index(item) + 1:xs.index(item) + 2] if xs[-1:] != item and item in xs else None
	if type(xs) == list:
		if item in xs and (not item == xs[-1]):
			return xs[xs.index(item) + 1]
		else:
			return None
	else:
		p = 0
		for k in xs:
			if p == 1:
				return k
			if k == item:
				p = 1
		return None


def next_item(xs, item):
	for (i, x) in enumerate(xs):
		try:
			if x == item and i != len(xs) - 1:
				return xs[i + 1]
		except:
			return next(xs)


def next_item(xs, item):
	it = iter(xs)
	return None if item not in it else next(it, None)


def next_item(xs, item):
	if item not in xs:
		return None
	if type(xs) in [str, list]:
		return None if item not in xs[:-1] else xs[xs.index(item) + 1]
	return next(xs)


def next_item(xs, item):
	mark = False
	for i in xs:
		if mark:
			return i
		if i == item:
			mark = True


def next_item(xs, item):
	found = False
	result = None
	for x in xs:
		if found:
			result = x
			break
		if x == item:
			found = True
	return result


def next_item(xs, item):
	if type(xs) == list:
		if xs.count(item) == 0:
			return None
		q = xs.index(item)
		if q + 1 >= len(xs):
			return None
		return xs[q + 1]
	else:
		qq = 0
		for i in xs:
			if i == item and qq == 0:
				qq = 1
				continue
			if qq == 1:
				return i
		return None


def next_item(xs, item):
	if type(xs) == str or type(xs) == list:
		if item not in xs or item == xs[-1]:
			return None
		elif type(xs) == str:
			return xs[xs.find(item) + 1]
		else:
			return xs[xs.index(item) + 1]
	primer_paso = next(xs)
	segundo_paso = next(xs)
	steps = segundo_paso - primer_paso
	if item in xs and item + steps in xs:
		return item + steps
	else:
		return None


def next_item(xs, item, flag=0):
	for i in xs:
		if flag == 1:
			return i
		if i == item:
			flag = 1


def next_item(xs, item):
	print((repr(xs), item))
	try:
		return xs[xs.index(item) + 1]
	except ValueError:
		return None
	except IndexError:
		return None
	except AttributeError:
		if repr(xs)[:5] == 'count':
			return item + 1
		else:
			try:
				i = 0
				while i != item:
					i = xs.__next__()
					if i == item:
						return xs.__next__()
			except StopIteration:
				return None


def next_item(xs, item):
	it = iter(xs)
	if item in it:
		try:
			return next(it)
		except:
			pass


def next_item(xs, item):
	print(isinstance(xs, range))
	i = 0
	for num in xs:
		if i == 1:
			return num
		if num == item:
			i += 1
	return None


def next_item(xs, item):
	it = iter(xs)
	for e in it:
		if e == item:
			break
	else:
		return
	for e in it:
		return e


def next_item(xs, item):
	if type(xs) is str:
		xs = [x for x in xs]
	if type(xs) is list:
		xs = (x for x in xs)
	for x in xs:
		if x == item:
			try:
				return next(xs)
			except StopIteration:
				return None
	return None


def next_item(xs, item):
	if type(xs) is str or type(xs) is list:
		for i in range(len(xs)):
			if xs[i] == item and xs.index(xs[i]) < xs.index(xs[-1]):
				return xs[i + 1]
		return None
	else:
		j = 0
		for j in xs:
			if j == item:
				return next(xs)