## Size of tuple

0 likes • Nov 19, 2022
Python

## More Python Posts

```import random
# Define the ranks, suits, and create a deckranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']deck = [(rank, suit) for rank in ranks for suit in suits]
# Shuffle the deckrandom.shuffle(deck)
# Display the shuffled deckfor card in deck:    print(card, "of", card)```
```class Solution(object):    def floodFill(self, image, sr, sc, newColor):        R, C = len(image), len(image)        color = image[sr][sc]        if color == newColor: return image        def dfs(r, c):            if image[r][c] == color:                image[r][c] = newColor                if r >= 1: dfs(r-1, c)                if r+1 < R: dfs(r+1, c)                if c >= 1: dfs(r, c-1)                if c+1 < C: dfs(r, c+1)
dfs(sr, sc)        return image```
```import calendar
# Prompt user for year and monthyear = int(input("Enter the year: "))month = int(input("Enter the month: "))
# Create a calendar objectcal = calendar.monthcalendar(year, month)
# Display the calendarprint(calendar.month_name[month], year)print("Mon  Tue  Wed  Thu  Fri  Sat  Sun")
for week in cal:    for day in week:        if day == 0:            print("     ", end="")        else:            print(str(day).rjust(2), "  ", end="")    print()```
```from colorama import init, Fore
# Initialize coloramainit()
print(Fore.RED + "This text is in red color.")print(Fore.GREEN + "This text is in green color.")print(Fore.BLUE + "This text is in blue color.")
# Reset coloramaprint(Fore.RESET + "This text is back to the default color.")```
```import itertoolsimport stringimport time
def guess_password(real):    chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation    attempts = 0    for password_length in range(1, 9):        for guess in itertools.product(chars, repeat=password_length):            startTime = time.time()            attempts += 1            guess = ''.join(guess)            if guess == real:                return 'password is {}. found in {} guesses.'.format(guess, attempts)            loopTime = (time.time() - startTime);            print(guess, attempts, loopTime)
print("\nIt will take A REALLY LONG TIME to crack a long password. Try this out with a 3 or 4 letter password and see how this program works.\n")val = input("Enter a password you want to crack that is 9 characters or below: ")print(guess_password(val.lower()))```
```from collections import defaultdict
def collect_dictionary(obj):  inv_obj = defaultdict(list)  for key, value in obj.items():    inv_obj[value].append(key)  return dict(inv_obj)  ages = {  'Peter': 10,  'Isabel': 10,  'Anna': 9,}collect_dictionary(ages) # { 10: ['Peter', 'Isabel'], 9: ['Anna'] }```