What will be the output of the following Python code snippet?
my_string = “hello world”
k = [(i.upper(), len(i)) for i in my_string]
print(k)
a) [(‘HELLO’, 5), (‘WORLD’, 5)]
b) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
c) [(‘HELLO WORLD’, 11)]
d) none of the mentioned
Answer: b
Explanation: We are iterating over each letter in the string.
Related Posts
JavaScript is a _______________ language.
What will be the output of the following JavaScript code?
function compare()
{
int a=1;
char b=1;
if(a.tostring()===b)
return true;
else
return false;
}The snippet that has to be used to check if “a” is not equal to “null” is _________
What will be the output of the following JavaScript code?
int a=1;
if(a!=null)
return 1;
else
return 0;The type of a variable that is volatile is _______________
Which of the following Attribute is used to include External JS code inside your HTML Document?
The escape sequence ‘\f’ stands for _________
Join The Discussion