0

I want to type a (from list1) and get 1 (from list2), and I don't want to use dict{zip(a,b)}. Is this possible? Don't want to type something like dict['a'], just a.

List1=['a', 'b', 'c']   
List2=[1, 24, 35]   
print(a)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    How about `a, b, c = 1, 24, 35`? – L.Grozinger Jul 19 '20 at 00:13
  • You could use an [`AttrDict`](https://stackoverflow.com/a/15109345/355230) which is `dict` subclass that would allow you to reference `my_attrdict.a` in addition to the usual `my_attrdict['a']`. – martineau Jul 19 '20 at 00:38
  • 1
    Dont dynamically create variables. If you want to map strings to other objects, use the appropriate container, in this case, a `dict` – juanpa.arrivillaga Jul 19 '20 at 00:51

2 Answers2

0

Try creating a function and passing the array and the string you want to fetch as a argument. Inside the function use a for-loop to match the items of the array and returning the matching item.

0

Assuming the lists are same length and the position are always aligned, you can do

List1=[a, b, c]   
List2=[1, 24, 35] 
List2[List1.index(a)]
sqz
  • 317
  • 5
  • 12