How to dynamically create a variable, initialize list and append elements to it using exec in python?

Shivani Jadhav
Jun 19, 2021

Consider you are given a string which should be converted into a variable. The following piece of code helps to achieve that.

A variable named ‘inc’ is created, given the string ‘inc’

Consider your are given a list of strings and each string should be converted into a list. Consider you are given a list of various country names and football players names. The problem statement is to create a list for each country and assign the football players to the list (It’s Euros2020 time!!!!!). For simplicity purpose, I have just taken 3 countries and another list has 3 football players where each footballer’s index corresponds to the country’s index.

A list with the respective football players is created given the country names

--

--

Shivani Jadhav

Data scientist Expertise : Information retrieval Area of interest-NLP, Machine learning, deep learning