Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I always use lists when coding but can never put into words when analyzing my own work. what is the definition of a list in detail?
It's a datatype that stores a bunch of stuff. The more general term is an 'array.'
In python, they are represented like so:
[1, 2, 3, 4, 'elem5', ['sub-list-item-1', 'sub-list-item-2'], {}]
One important aspect of lists is that they can contain any type of data, or mixed data types.
Python docs define a list thusly:
list
A built-in Python sequence. Despite its name it is more akin to
an array in other languages than to a linked list since access to
elements are O(1).
Read More Here
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I'm new to python, and I'm a bit confused about the use cases of data types in python
Can someone please explain in detail when to use each data type, with an example if possible
Thank you.
Lists are used when you have data you want to further modify, alter like sorting and all.
Dictionary is used when you have to sets of data where data of the first set corresponds to data of other set. And the position of the data doesn't matter only the relation of the two sets matters.
A tuple is used when position of the data is very important and you don't want to alter the position throughout.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am working on a machine learning task and trying to convert all strings in a set of data to floats using hash() to do this I need to iterate over all the elements of a numpy array whilst not knowing if it is a 2D 3D or 4D array and then change each element. Is there any way to do this without using nested loops?
You can try numpu.vectorize, already mentioned here
Note:
The vectorize function is provided primarily for convenience, not for performance. The implementation is essentially a for loop.here
arr = np.array([['aba', 'baa', 'bbb'],
['xxy', 'xyy', 'yyy']])
v_hash = np.vectorize(hash)
v_hash(arr)
array([[-1538054455328520296, -1528482088733019667, -7962229468338304433],
[ 5621962119614158870, 1918700875003591346, -3216770211373729154]])
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Suppose I have the some code in which I used map() function.
I know I can later print it by converting it to list just like this :
get_something = map(some_function, some_list)
print(list(get_something))
But Is there any way other than list. I mean what if I want to print not as list but line by line and don't want to use for loop every now and then?
Why dont you try this:
print(*map(some_function, some_list),sep='\n')
By this print() will refer to map object and will print values with \n as a separator
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have list, its elements are also a list.
eg:
outlier=[[20,2,67], [90,6,12], [23,16,7]].
how I write a single line code to loop outlier list by taking elements from same index.I want to store the looping result as a list.
The question is not very clear to me, but if you want to make a new list that contains the first element of each list you have, then this is an example to take first element(x[0]) from each list and store them in a new list called "new_list":
new_list = [x[0] for x in outlier]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Read each line in a text file, store the values in a list, and compute scores
The best approach this problem is to list all the functions you need to do the task. A typical example is:
Read file.
Read list.
Take list and get each string delimited by space.
Store string into an array.
...
Then go to the Python website and lookup how to do each function.
Example: To do input and output function in python:
https://docs.python.org/2/tutorial/inputoutput.html
Also, you can look up function by asking google. Google will then point you to answers to your questions:
Q: How to find mean of a list?
A: Finding the average of a list
If you do this enough times, eventually you will be able to write a problem that solves the problem listed.
Good Luck!