switching keys and values in a dictionary in python [duplicate]
my_dict = {2:3, 5:6, 8:9}
new_dict = {}
for k, v in my_dict.items():
new_dict[v] = k
switching keys and values in a dictionary in python [duplicate]
my_dict = {2:3, 5:6, 8:9}
new_dict = {}
for k, v in my_dict.items():
new_dict[v] = k
difference between foreach and map in js
forEach() just loop through the elements. It's throws away return values and always returns undefined.The result of this method does not give us an output .
map() loop through the elements allocates memory and stores return values by iterating main array
Example:
var numbers = [2,3,5,7];
var forEachNum = numbers.forEach(function(number){
return number
})
console.log(forEachNum)
//output undefined
var mapNum = numbers.map(function(number){
return number
})
console.log(mapNum)
//output [2,3,5,7]
map() is faster than forEach()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us