Create vars based on number of elements on the list

0 votes
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 by Ashish
488 views

1 answer to this question.

0 votes

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

Related Questions In Python

0 votes
1 answer

How do I get the number of elements in a list?

Hello, The len() function can be used with several different ...READ MORE

answered Nov 18, 2020 in Python by Niroj
• 82,840 points
644 views
0 votes
1 answer

How do I get the number of elements in a list

items = [] items.append("apple") items.append("orange") items.append("banana") len(items) #use the ...READ MORE

answered Feb 15, 2022 in Python by Dev
• 6,000 points
669 views
0 votes
1 answer

How do I get the number of elements in a list

The len() function can be used with several different ...READ MORE

answered Feb 15, 2022 in Python by CoolCoder
• 4,420 points
604 views
0 votes
1 answer

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

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

answered Sep 22, 2018 in Python by SDeb
• 13,300 points
5,030 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

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

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,423 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

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

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,042 views
0 votes
1 answer

How to count the number of elements in a list?

To count the number of elements of ...READ MORE

answered May 27, 2019 in Python by Nisa
• 1,090 points
5,237 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
1,406 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP