Skip to main content
rewrite as one-liner
Source Link
0 _
  • 11.8k
  • 12
  • 85
  • 112

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turn_to_dict(*args):   my_dict =return {} i: v for posi, v in xrange(lenenumerate(args)):}  lst1 = [1, 2, 3, 4] lst2 = [3, my_dict[pos]4, =6, args[pos]7] returnlst3 my_dict= [5, 8, 9] printv = turn_to_dict(lst1, lst2, lst3) # >>> print(v) {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turn_to_dict(*args):   my_dict = {}  for pos in xrange(len(args)): my_dict[pos] = args[pos] return my_dict print turn_to_dict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

def turn_to_dict(*args): return {i: v for i, v in enumerate(args)}  lst1 = [1, 2, 3, 4] lst2 = [3, 4, 6, 7] lst3 = [5, 8, 9] v = turn_to_dict(lst1, lst2, lst3)  >>> print(v) {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

If you want to turn the variable name into a key, here is a similar questionsimilar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turn_to_dict(*args): my_dict = {} for pos in xrange(len(args)): my_dict[pos] = args[pos] return my_dict print turn_to_dict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turn_to_dict(*args): my_dict = {} for pos in xrange(len(args)): my_dict[pos] = args[pos] return my_dict print turn_to_dict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turn_to_dict(*args): my_dict = {} for pos in xrange(len(args)): my_dict[pos] = args[pos] return my_dict print turn_to_dict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 
added 13 characters in body
Source Link
Padraic Cunningham
  • 181.2k
  • 30
  • 264
  • 327

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turnToDictturn_to_dict(*args): dictmy_dict = {} for pos in xrange(len(args)): dict[pos]my_dict[pos] = args[pos] return dictmy_dict print turnToDictturn_to_dict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turnToDict(*args): dict = {} for pos in xrange(len(args)): dict[pos] = args[pos] return dict print turnToDict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 

If you want to turn the variable name into a key, here is a similar question.

If you just want a dictionary of lists with a sequential key.

lst1 = [1,2,3,4] lst2 = [3,4,6,7] lst3 = [5,8,9] def turn_to_dict(*args): my_dict = {} for pos in xrange(len(args)): my_dict[pos] = args[pos] return my_dict print turn_to_dict(lst1, lst2, lst3) # {0: [1, 2, 3, 4], 1: [3, 4, 6, 7], 2: [5, 8, 9]} 
Source Link
GGhe
  • 693
  • 5
  • 19
Loading