# Introduction and Warm-up (Highly recommended)

# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___

# Task

**_Given_** an *array/list [] of integers* , **_Find_**  *the Nth smallest element in this array of integers*
___

# Notes 

* **_Array/list_** size is *at least 3* .

* **_Array/list's numbers_** *could be a **_mixture_** of positives , negatives and zeros* .

* **_Repetition_** *in array/list's numbers could occur* , so **_don't Remove Duplications_** .
___

# Input >> Output Examples

```
nthSmallest({3,1,2} ,2) ==> return (2) 
```

## **_Explanation_**:

Since the passed number is **_2_** , Then * **_the second smallest_** element in this array/list is **_2_***  
___

```
nthSmallest({15,20,7,10,4,3} ,3) ==> return (7) 
```

## **_Explanation_**:

Since the passed number is **_3_** , Then * **_the third smallest_** element in this array/list is **_7_*** 
___
```
nthSmallest({2,169,13,-5,0,-1} ,4) ==> return (2) 
```

## **_Explanation_**:

Since the passed number is **_4_** , Then * **_the fourth smallest_** element in this array/list is **_2_*** 
___

```
nthSmallest({177,225,243,-169,-12,-5,2,92} ,5) ==> return (92) 
```
## **_Explanation_**:

Since the passed number is **_5_** , Then * **_the fifth smallest_** element in this array/list is **_92_*** 
___
___
___

# [Playing with Numbers Series](https://www.codewars.com/collections/playing-with-numbers)

# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)

# [For More Enjoyable Katas](http://www.codewars.com/users/MrZizoScream/authored)
___

## ALL translations are welcomed

## Enjoy Learning !!
# Zizou

Difficulty: EASY
Tags: Fundamentals

Data structures
Skill types: Data structures

Starter code:
def nth_smallest(arr, pos):
	

Solutions:
def nth_smallest(arr, pos):
	return sorted(arr)[pos - 1]


from heapq import nsmallest

def nth_smallest(arr, pos):
	return nsmallest(pos, arr)[-1]


def nth_smallest(arr, pos):
	arr.sort()
	return arr[pos - 1]


import random

def quick_select(arr, pos):
	pivot = random.choice(arr)
	less = []
	greater = []
	k = 0
	if len(arr) == 1:
		return arr[0]
	for i in arr:
		if i < pivot:
			less.append(i)
		elif i > pivot:
			greater.append(i)
		else:
			k += 1
	if pos < len(less):
		return quick_select(less, pos)
	elif pos < len(less) + k:
		return pivot
	else:
		return quick_select(greater, pos - len(less) - k)

def nth_smallest(arr, pos):
	return quick_select(arr, pos - 1)

def __starting_point():
	print(nth_smallest([15, 20, 7, 10, 4, 3], 3))
__starting_point()


def nth_smallest(arr, pos):
	if len(arr) == 1:
		return arr[0]
	pivot_value = arr[0]
	smaller = [num for num in arr[1:] if num < pivot_value]
	bigger = [num for num in arr[1:] if num > pivot_value]
	count_smaller_or_equal = len(arr) - len(bigger)
	if len(smaller) > pos - 1:
		return nth_smallest(smaller, pos)
	elif count_smaller_or_equal > pos - 1:
		return pivot_value
	else:
		return nth_smallest(bigger, pos - count_smaller_or_equal)


def nth_smallest(a, n):
	return sorted(a)[n - 1]


def nth_smallest(lst, pos):
	return sorted(lst)[pos - 1]


nth_smallest = lambda a, p: sorted(a)[p - 1]


def nth_smallest(arr, pos):
	if pos > len(arr):
		return max(arr)
	if len(arr) == 1:
		return arr[0]
	pivot = arr[len(arr) // 2]
	lit = [i for i in arr if i < pivot]
	big = [i for i in arr if i > pivot]
	k = len(arr) - len(big)
	if pos > k:
		return nth_smallest(big, pos - k)
	elif pos > len(lit):
		return pivot
	else:
		return nth_smallest(lit, pos)


from random import choice

def nth_smallest(arr, pos):
	ar = list(arr)
	while True:
		if len(ar) == 1:
			return ar[0]
		(big, lit, pivot) = ([], [], choice(ar))
		for i in ar:
			if i > pivot:
				big.append(i)
			elif i < pivot:
				lit.append(i)
		k = len(ar) - len(big)
		if pos > k:
			(ar, pos) = (big, pos - k)
		elif pos > len(lit):
			return pivot
		else:
			ar = lit


def nth_smallest(arr, pos):
	return __import__('heapq').nsmallest(pos, arr)[-1]


nth_smallest = lambda *a: sorted(a[0]).pop(a[1] - 1)


nth_smallest = lambda a, i: sorted(a).pop(i - 1)


def nth_smallest(arr, pos):
	i = (pos - len(arr) if pos >= len(arr) else pos) - 1
	x = sorted(arr)
	return min(x[i:])


def nth_smallest(arr, pos):
	res = 0
	for _ in range(pos):
		res = min(arr)
		arr.remove(min(arr))
	return res


def nth_smallest(ls, nth):
	return sorted(ls)[nth - 1]


import heapq

def nth_smallest(arr, pos):
	heap = heapq.nsmallest(pos, arr)
	return heap[-1]


def nth_smallest(arr, pos):
	x = sorted(arr)
	steps = 1
	for i in x:
		if steps == pos:
			return i
		else:
			steps += 1


def nth_smallest(arr, pos):
	a = sorted(arr)
	print(a)
	return a[pos - 1]


import heapq

def nth_smallest(nlist, num):
	return heapq.nsmallest(num, nlist)[-1]


def nth_smallest(arr, pos):
	arr = sorted(arr)
	for (i, j) in enumerate(arr):
		if i == pos - 1:
			return j


import numpy as np

def nth_smallest(arr, pos):
	res = np.sort(arr)
	d = res[pos - 1]
	return d


def nth_smallest(arr: list, pos: int):
	return sorted(arr)[pos - 1]


from heapq import nsmallest
from typing import List

def nth_smallest(arr: List[int], pos: int) -> int:
	return nsmallest(pos, arr)[-1]


from heapq import nsmallest
nth_smallest = lambda lst, n: nsmallest(n, lst)[-1]


def merged(p, q):
	pc = 0
	qc = 0
	ra = []
	while True:
		if pc < len(p) and qc < len(q):
			if p[pc] < q[qc]:
				ra.append(p[pc])
				pc = pc + 1
			else:
				ra.append(q[qc])
				qc = qc + 1
		elif pc < len(p):
			ra.append(p[pc])
			pc = pc + 1
		elif qc < len(q):
			ra.append(q[qc])
			qc = qc + 1
		else:
			break
	return ra

def mysort(arr):
	if len(arr) < 2:
		return arr
	else:
		mid = len(arr) // 2
		part1 = mysort(arr[:mid])
		part2 = mysort(arr[mid:])
		return merged(part1, part2)

def nth_smallest(arr, pos):
	arr = mysort(arr)
	return arr[pos - 1]


def nth_smallest(arr, n):
	return sorted(arr)[n - 1]


nth_smallest = lambda r, i: sorted(r)[i - 1]


def nth_smallest(arr, pos):
	i = 0
	a = 0
	while i < pos:
		a = min(arr)
		arr.remove(a)
		i += 1
	return a


def nth_smallest(arr, pos):
	sar = sorted(arr)
	return sar.pop(pos - 1)


def nth_smallest(x, y):
	return sorted(x)[y - 1]


def nth_smallest(arr, pos):
	for i in range(pos):
		x = min(arr)
		arr.remove(x)
	return x


def nth_smallest(arr, pos):
	sort = sorted(arr, reverse=True)
	return sort[-pos]


def nth_smallest(arr, pos):
	arr.sort()
	min = 0
	for i in range(len(arr)):
		pos -= 1
		if pos == 0:
			min = arr[i]
			break
	return min


from heapq import nsmallest

def nth_smallest(a, p):
	return nsmallest(p, a)[-1]


def nth_smallest(arr, pos):
	arr.sort()
	lol = arr[0:pos]
	return lol[pos - 1]


def nth_smallest(arr, pos):
	if len(arr) < 3:
		return 'Array needs to be longer'
	a = sorted(arr)
	real_index = pos - 1
	b = a[real_index]
	return b


def nth_smallest(arr, pos):
	while pos > 1:
		arr.remove(min(arr))
		if len(arr) < 2:
			return arr[0]
		pos -= 1
	return min(arr)


def nth_smallest(arr, n):
	if n == 1:
		return min(arr)
	del arr[arr.index(min(arr))]
	return nth_smallest(arr, n - 1)


def nth_smallest(arr, pos):
	for i in range(pos):
		result = min(arr)
		arr.remove(result)
	return result


def nth_smallest(arr, pos):
	for a in range(pos):
		index = arr.pop(arr.index(min(arr)))
	return index


import heapq

def nth_smallest(arr, pos):
	x = heapq.nsmallest(pos, arr)
	print(x)
	return x[-1]


def nth_smallest(arr, pos):
	ref = pos - 1
	arr.sort(reverse=False)
	return arr[ref]


def nth_smallest(arr, pos):
	for number in arr:
		if pos == 1:
			return min(arr)
		elif pos > 1:
			for to_delete in range(1, pos):
				arr.remove(min(arr))
			return min(arr)


def nth_smallest(arr, pos):
	for _ in range(pos - 1):
		arr.remove(min(arr))
	return min(arr)


def nth_smallest(arr, k):
	return sorted(arr)[k - 1]


def nth_smallest(arr, pos):
	new_list = sorted(arr, reverse=True)
	return new_list[-pos]


def nth_smallest(arr, pos):
	for i in range(len(arr) - pos):
		arr.remove(max(arr))
	return max(arr)


def nth_smallest(arr, pos):
	m = 0
	while pos != 0:
		m = min(arr)
		arr.pop(arr.index(m))
		pos -= 1
	return m


def nth_smallest(arr, pos):
	arr.sort()
	for i in range(len(arr)):
		if i + 1 == pos:
			return arr[i]


def nth_smallest(arr, pos):
	i = pos
	while i > 0:
		result = min(arr)
		arr.remove(min(arr))
		i -= 1
	return result


def nth_smallest(a, b):
	a.sort()
	return a[b - 1]


def nth_smallest(arr, pos):
	for i in range(0, len(sorted(arr))):
		if i == pos - 1:
			return sorted(arr)[i]


def nth_smallest(arr, pos):
	arr.sort()
	[arr.pop(0) for _ in range(pos - 1)]
	return arr[0]


def nth_smallest(list, pos):
	list.sort()
	return list[pos - 1]


def nth_smallest(arr, pos):
	if pos > len(arr):
		return sorted(arr)[-1]
	else:
		return sorted(arr)[pos - 1]


def nth_smallest(arr, pos):
	sorted_arr = sorted(arr)
	while pos > 1:
		sorted_arr.pop(0)
		pos -= 1
	return sorted_arr.pop(0)


def nth_smallest(arr, pos):
	result = None
	if pos <= len(arr):
		arr.sort()
		result = arr[pos - 1:][0]
	return result


def nth_smallest(arr, pos):
	return sorted(arr, reverse=True)[pos * -1]


def nth_smallest(arr, pos):
	newlis = []
	newlis = list(arr)
	newlis.sort()
	return newlis[pos - 1]


def nth_smallest(arr, pos):
	arr.sort()
	count = 1
	for x in arr:
		if count == pos:
			return x
		else:
			count += 1


def nth_smallest(arr, pos):
	l = len(arr)
	liste = arr
	n = 1
	while n != pos:
		liste.remove(min(liste))
		n = n + 1
	return min(liste)


def nth_smallest(arr, pos):
	while pos > 0:
		m = min(arr)
		arr.remove(m)
		pos -= 1
	return m


def sel_sort(array):
	for i in range(len(array) - 1):
		m = i
		j = i + 1
		while j < len(array):
			if array[j] < array[m]:
				m = j
			j = j + 1
		(array[i], array[m]) = (array[m], array[i])

def nth_smallest(arr, pos):
	if pos <= 0 or arr == []:
		return 'error'
	sel_sort(arr)
	return arr[pos - 1]


import pandas as pd

def nth_smallest(arr, pos):
	arr_series = pd.Series(arr)
	return arr_series.sort_values(ascending=True).reset_index(drop=True)[pos - 1]


def nth_smallest(list1, num):
	a = list(list1)
	a.sort()
	return a[num - 1]


def nth_smallest(arr, pos):
	minimum = 0
	for i in range(pos):
		minimum = minimum_k(arr)
	return minimum

def minimum_k(array):
	minimum = 99999
	for i in array:
		minimum = min(minimum, i)
	array.remove(minimum)
	return minimum


def nth_smallest(arr, pos):
	smallest = [0]
	small = 0
	for i in range(len(arr)):
		smallest.append(min(arr))
		arr.pop(arr.index(min(arr)))
	return smallest[pos]


def nth_smallest(arr, pos):
	arr.sort()
	newPos = pos - 1
	nSmall = arr[newPos]
	return nSmall


import numpy as np

def nth_smallest(arr, pos):
	arr = sorted(arr)
	return arr[pos - 1]


def nth_smallest(arr, pos):
	b = sorted(arr)
	a = b[pos - 1]
	return a


def nth_smallest(arr, pos):
	res = list(arr)
	i = 1
	while i < pos:
		m = min(res)
		for (k, x) in enumerate(res):
			if x == m:
				res[k] = 999999999
				break
		i = i + 1
	return min(res)