Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //python code
- def new_list(n):
- n_dict = {}
- n_dict['words'] = []
- n_dict['numbers'] = []
- for i in n:
- if i == str(i):
- n_dict['words'].append(i)
- else:
- n_dict['numbers'].append(i)
- return n_dict
- // javaScript
- function new_list(n){
- var dict = {};
- dict.words = [];
- dict.numbers = [];
- for(var i in n){
- if (i == str(i)){
- dict.words.push(i);
- }
- else{
- dict.numbers.push(i);
- }
- }
- return dict;
- }
- var m = ["book", 4, "hook", 4.5]
- console.log(new_list(m))
- m = ["book", 4, "hook", 4.5]
- print(new_list(m))
- //my problem is the str function is not valid in javascript, what do should i use. i want the result to be
- dict = { 'words' : ["books", "hooks"], 'numbers': [4, 4.5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement