This question already has answers here:
What does it mean to unpack in python?
(5 answers)
List comprehension rebinds names even after scope of comprehension. Is this right?
(6 answers)
Closed 5 months ago.
I was trying to make a code that allows multiple user inputs in different variables in only one line in Python. I've studied a bit of list comprehension, but I can't understand how the code below works.
a,b,c = [int(a) for a in input().split()]
Why is the output an integer value of a, b, and c if only a is being put into the loop?
Related
This question already has answers here:
Python: Short way of creating a sequential list with a prefix
(3 answers)
Create a list of strings with consecutive numbers appended
(6 answers)
Appending the same string to a list of strings in Python
(12 answers)
Closed 7 months ago.
In Python how can I need to create a long list that I'm trying to avoid typing, the list looks lis this
brands = ['_1','_2','_3'... '_998']
I can create the list of numbers with a for loop, but I'm trying to use list comprehension for the characters which should be faster.
Thanks!
my list=["_" + str(i) for i in range(1,999)]
This question already has answers here:
How can I get list of values from dict?
(7 answers)
Why does map return a map object instead of a list in Python 3?
(4 answers)
Closed 3 years ago.
I have recently started using python 3 and while working on list comprehension I am seeing something completely different from python 2. I want to know why is it that while printingthe value of 'y' python3 is returning [dict_values([1]), dict_values([2])] instead of [1,2] and how I can get response in desired form i.e,[1,2]
>>> x=[{'x':1},{'y':2}]
>>> y=[i.values() for i in x]
>>> y
[dict_values([1]), dict_values([2])]
This question already has answers here:
How do you create different variable names while in a loop? [duplicate]
(9 answers)
How do I create variable variables?
(17 answers)
Closed 4 years ago.
As of right now i am a beginner with python. I wanna make a giant list of variables without having to write out each one, so far heres the idea:
n=0
i=None
for i in range(10):
n = n + 1
x="hi"
var = x+"{0}".format(n)
print(var)
the output are strings but i want to make them variable that i can define freely. Any pointers>
This question already has answers here:
How do I create variable variables?
(17 answers)
How can I create multiple variables from a list of strings? [duplicate]
(2 answers)
Closed 5 years ago.
I'm a rookie at Python so I don't know much about the limits of the language, but it seems that you can't write a function or a program that creates a list on its own.
I'm working with binary lists. I'm working with 7 bits so, as you can guess, I need 128 different lists to store all possibilities.
Let me know if its possible, or if not please let me know why and what else could work for my needs.
def list_creator:
n=128
"create a new_list n times with 7 of length"
"Should display something like this"
list1=[None]*7
list2=[None]*7
list(n)=[None]*7
You should make a list containing 128 empty lists and add to those.
This question already has answers here:
What does asterisk * mean in Python? [duplicate]
(5 answers)
Closed 5 years ago.
I have a list of names and I want to print each element of the list in a different line without a for loop. So, after some research I found this example: print(*names, sep='\n'), witch results in exactly what I want. But what does this * character before the list name means?
The * is used to unpack argument lists when calling a function. In this case it unpacks your list of names.