9 examples of 'how to make a list of a certain length in python' in Python

Every line of 'how to make a list of a certain length in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
170def makeList(input):
171 if isinstance(input, basestring):
172 return [ input ]
173 elif input is None:
174 return [ ]
175 else:
176 return list(input)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

13def to_list(l):
14 return isinstance(l, list) and l or [l]
22def bunch(lst, size):
23 size = int(size)
24 return [lst[i:i+size] for i in range(0, len(lst), size)]
814def unlist(l):
815 """
816 Macht aus einer Liste mit nur einem Element einen Skalar.
817 """
818 if len(l) == 1:
819 return l[0]
820 return l
3def newlist(size):
4 list = []
5 for i in range(size):
6 list.append(i)
7 return list
76def make_list(**kwargs):
77 return [
78 {
79 "value": ["hello", "world"],
80 "simplified": (
81 CODE[list],
82 ((CODE[str], (b"hello",)), (CODE[str], (b"world",))), # item
83 ),
84 },
85 {"value": ["hello"], "simplified": (CODE[list], ((CODE[str], (b"hello",)),))}, # item
86 {"value": [], "simplified": (CODE[list], tuple())},
87 # Tests that forced full simplify should return just simplified object if it doesn't have full simplifier
88 {
89 "forced": True,
90 "value": ["hello"],
91 "simplified": (CODE[list], ((CODE[str], (b"hello",)),)), # item
92 },
93 ]
26def listify(l):
27 if isinstance(l, types.StringTypes):
28 l = [l]
29 return l
456def allocate_python(value):
457 assert not isinstance(value, str), (type(value), repr(value))
458 # Allocate some handle to hold VALUE, return its index.
459 if freed_list:
460 index = freed_list[-1]
461 del freed_list[-1]
462 python[index] = value
463 else:
464 index = len(python)
465 python.append(value)
466 return index
54def test_to_list_one_item(lla):
55 lla.append(1)
56
57 assert lla.to_list() == [1]

Related snippets