A great flood has hit the land, and just as in Biblical times we need to get the animals to the ark in pairs. We are only interested in getting one pair of each animal, and not interested in any animals where there are less than 2....they need to mate to repopulate the planet after all!

You will be given a list of animals, which you need to check to see which animals there are at least two of, and then return a dictionary containing the name of the animal along with the fact that there are 2 of them to bring onto the ark.

---

```python
>>> two_by_two(['goat', 'goat', 'rabbit', 'rabbit', 'rabbit', 'duck', 'horse', 'horse', 'swan'])
{'goat': 2, 'horse': 2, 'rabbit': 2}

# If the list of animals is empty, return False as there are no animals to bring onto the ark and we are all doomed!!!
>>> two_by_two([])
False

# If there are no pairs of animals, return an empty dictionary
>>> two_by_two(['goat'])
{}
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def two_by_two(animals):
	

Solutions:
def two_by_two(animals):
	return {x: 2 for x in animals if animals.count(x) > 1} if animals else False


from collections import Counter

def two_by_two(animals):
	return bool(animals) and {key: 2 for (key, value) in Counter(animals).items() if value >= 2}


def two_by_two(animals):
	return {animal: 2 for animal in set(animals) if animals.count(animal) > 1} if len(animals) else False


from collections import Counter

def two_by_two(a):
	return {x: 2 for (x, y) in Counter(a).items() if y > 1} if a else 0


from collections import Counter

def two_by_two(animals):
	if not animals:
		return False
	return {animal: 2 for (animal, count) in Counter(animals).items() if count > 1}


from collections import Counter

def two_by_two(animals):
	if not animals:
		return False
	return {k: 2 for (k, v) in Counter(animals).items() if v >= 2}


two_by_two = lambda a: a > [] and {k: 2 for k in a if a.count(k) > 1}


from collections import *
two_by_two = lambda a: a > [] and {k: 2 for (k, v) in Counter(a).items() if v > 1}


from collections import Counter

def two_by_two(animals):
	return bool(animals) and dict(((k, 2) for (k, v) in Counter(animals).items() if v >= 2))