I am trying to create a python logic such that it creates variables based on the number of elements in the list. How do I do that?
Jul 23, 2019 in Python 30 views

## 1 answer to this question.

Hey @Ashish, you can try something like this:

```list = [1, 2, 3, 4]
d = {'var%d' % el: None for el in list}
d
{'var4': None, 'var1': None, 'var3': None, 'var2': None}```
answered Jul 23, 2019 by Haseeb

## Return a list inside a for loop while iterating over the elements of another list

The print() is getting called multiple times ...READ MORE

## How to get the multiplication table of any number using list comprehension?

Hey @Neha, you can use something like ...READ MORE

+1 vote

## Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

+1 vote

## Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE