Software Development Exam  >  Software Development Questions  >  import hashlibdef hash_string(s): return has... Start Learning for Free
import hashlib
def hash_string(s):
    return hashlib.md5(s.encode()).hexdigest()
hash_table = [[] for _ in range(5)]
keys = ['apple', 'banana', 'cherry', 'date']
for key in keys:
    index = int(hash_string(key), 16) % 5
    hash_table[index].append(key)
print(hash_table)
What will be the output of the above code?
  • a)
    [[], ['apple'], [], ['banana'], ['cherry', 'date']]
  • b)
    [[], ['apple', 'cherry'], ['banana'], [], ['date']]
  • c)
    [['banana', 'cherry'], [], [], ['apple'], ['date']]
  • d)
    [['banana'], ['cherry'], ['date'], ['apple'], []]
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexd...
The code demonstrates hash table implementation using the MD5 hashing algorithm. The hash_string() function converts a string into its MD5 hash. The keys from the keys list are hashed, and the resulting hash values are converted to integers and used as indices to append the keys to the appropriate buckets in the hash_table.
View all questions of this test
Explore Courses for Software Development exam

Top Courses for Software Development

Question Description
import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? for Software Development 2025 is part of Software Development preparation. The Question and answers have been prepared according to the Software Development exam syllabus. Information about import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Software Development 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer?.
Solutions for import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Software Development. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free.
Here you can find the meaning of import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer?, a detailed solution for import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice import hashlibdef hash_string(s): return hashlib.md5(s.encode()).hexdigest()hash_table = [[] for _ in range(5)]keys = [apple, banana, cherry, date]for key in keys: index = int(hash_string(key), 16) % 5 hash_table[index].append(key)print(hash_table)What will be the output of the above code?a)[[], [apple], [], [banana], [cherry, date]]b)[[], [apple, cherry], [banana], [], [date]]c)[[banana, cherry], [], [], [apple], [date]]d)[[banana], [cherry], [date], [apple], []]Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Software Development tests.
Explore Courses for Software Development exam

Top Courses for Software Development

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev