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]
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:
Append a dictionary to a dictionary [duplicate]
(7 answers)
How to index into a dictionary?
(11 answers)
Closed 2 months ago.
I encountered a program where I had to append one dictionary into another, and I was unable to do it because I could not use indexing in dictionary so I wanted to know what the possible ways are I could do it
This question already has answers here:
How to get first AND last element of tuple at the same time
(4 answers)
Closed 1 year ago.
Is there a function in Python to do it?
I have tried printing out last item in the tuple, but each time I want to generate more strings, I have to change it manually.
Try tuple_name[-1]
replace tuple_name with your tuple name
finally, it will be like print(tuple_name[-1])
This question already has answers here:
How do you pick "x" number of unique numbers from a list in Python?
(7 answers)
Closed 6 years ago.
I was wondering how I'd select a set number of variables out of a list using python
For example:
If my list was - list=["a","b","c"]
and I wanted to select 2 of the variables I the list how would I do so?
import random
random.sample(set(list), 2)
This will select random two values from 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)