This question already has answers here:
How do I iterate through two lists in parallel?
(8 answers)
Closed 4 years ago.
Basically, I want something along the lines of:
for coin in all_coins["result"] and coin2 in all_coins2["result"]:
specifiedlist.append(Crypto(coin, coin2))
Any help pointing me into the direction of a proper function or formatting would be appreciated.
You can use itertools.product to create your permutations in a list comprehension
from itertools import product
specifiedlist = [Crypto(coin, coin2) in product(all_coins["result"], all_coins2["result"])]
Related
This question already has answers here:
python order of elements in set
(2 answers)
Why is the order in dictionaries and sets arbitrary?
(5 answers)
Closed 26 days ago.
I have a list a:
a={4941, 4980, 3855, 4763, 4955}
I convert into a list:
b=list(a)
b now becomes [4980, 4955, 4763, 4941, 3855]
Sorry am I missing something? Eventhough set is an unordered structure why should it change the order ? Or is it the list function that is doing this?
Sorry if this is too naive a question! Many thanks.
This question already has answers here:
Sum a list of numbers in Python
(26 answers)
Closed 5 months ago.
I am using a for loop to fill a list with 100 random numbers. I want to add those numbers once the list is complete and I cannot figure out how to do that. I am pretty sure it is something simple that I have just overlooked but it is driving me crazy that I can't get it to work.
Use sum(list)
list = [random.randint(1,9) for i in range(100)]
print(sum(list))
Python has a built in sum function
list_sum = sum(your_list)
This question already has answers here:
Access item in a list of lists
(8 answers)
Closed 1 year ago.
stats=[[5,1,4],[3,4,3],[2,3,5]]
I was just wondering how I would select an element and I can't find anything that will help. for example, how would I select the 2 in the last set of numbers
its called 2 dimensional list and below is the way. thanks
stats[2][0]
This question already has answers here:
How to convert nested list of lists into a list of tuples in python 3.3?
(4 answers)
Closed 6 years ago.
I want to convert a list of list into list of tuples using Python. But I want to do it without iterating through the nested list as it will increasing execution time of script. Is there any way which can workout for me?
Thanks in Advance
converted_list = [tuple(i) for i in nested_list]
This question already has answers here:
How to extract parameters from a list and pass them to a function call [duplicate]
(3 answers)
Closed 7 years ago.
I have a parameter list which is just inputs separated by commas.
Now that I have a non-empty list, myList[], how do I turn the entries of L into a parameter list?
Example: if want
myList[0], myList[1], myList[2]..., myList[10]
How can I do that? Thank you! Is there anything similar to unpacking?
You can use unpacking with *.
f(*myList)