[HackerRank] All Domains - Python - Basic Data Types - Tuples

2022. 3. 13. 16:22Algorithm

728x90
반응형

Tuples are data structures that look a lot like lists. Unlike lists, tuples are immutable (meaning that they cannot be modified once created). This restricts their use because we cannot add, remove, or assign values; however, it gives us an advantage in space and time complexities.

A common tuple use is the swapping of  numbers:

a, b = b, a 

Here  is a tuple, and it assigns itself the values of .

Another awesome use of tuples is as keys in a dictionary. In other words, tuples are hashable.

 

 

--------------------------------------------

inputvalue=int(input())nlist=[]mlist=[]x=0nlist=input().split()while (x<inputvalue):    mlist.insert(x,int(nlist[x]))    x+=1;contuple=tuple(mlist)

 

print(hash(contuple))

---------------------------------------------

728x90
반응형