|
1074 | 1074 | "sums(1, 3, 4)" |
1075 | 1075 | ] |
1076 | 1076 | }, |
| 1077 | + { |
| 1078 | + "cell_type": "markdown", |
| 1079 | + "metadata": { |
| 1080 | + "ExecuteTime": { |
| 1081 | + "end_time": "2019-06-08T09:10:40.356028Z", |
| 1082 | + "start_time": "2019-06-08T09:10:40.342374Z" |
| 1083 | + } |
| 1084 | + }, |
| 1085 | + "source": [ |
| 1086 | + "#### Q.29. What naive data structures can you name in python?\n", |
| 1087 | + "Common native data structures in Python are as follows:\n", |
| 1088 | + "- Dictionaries\n", |
| 1089 | + "- Lists\n", |
| 1090 | + "- Sets\n", |
| 1091 | + "- Strings\n", |
| 1092 | + "- Tuples\n", |
| 1093 | + "\n", |
| 1094 | + "##### Of these, which are mutable, and which are immutable?\n", |
| 1095 | + "Lists, dictionaries, and sets are mutable. This means that you can change their content without changing their identity. Strings and tuples are immutable, as their contents can’t be altered once they’re created." |
| 1096 | + ] |
| 1097 | + }, |
| 1098 | + { |
| 1099 | + "cell_type": "markdown", |
| 1100 | + "metadata": {}, |
| 1101 | + "source": [ |
| 1102 | + "#### Q.30. When would you use a List vs. a Tuple vs. a Set in Python?\n", |
| 1103 | + "A list is a common data type that is highly flexible. It can store a sequence of objects that are mutable, so it’s ideal for projects that demand the storage of objects that can be changed later.\n", |
| 1104 | + "\n", |
| 1105 | + "A tuple is similar to a list in Python, but the key difference between them is that tuples are immutable. They also use less space than lists and can only be used as a key in a dictionary. Tuples are a perfect choice when you want a list of constants.\n", |
| 1106 | + "\n", |
| 1107 | + "Sets are a collection of unique elements that are used in Python. Sets are a good option when you want to avoid duplicate elements in your list. This means that whenever you have two lists with common elements between them, you can leverage sets to eliminate them." |
| 1108 | + ] |
| 1109 | + }, |
| 1110 | + { |
| 1111 | + "cell_type": "markdown", |
| 1112 | + "metadata": {}, |
| 1113 | + "source": [ |
| 1114 | + "#### Q.31. What packages in the standard library, useful for data science work, do you know?\n", |
| 1115 | + "- Numpy\n", |
| 1116 | + "- Pandas\n", |
| 1117 | + "- Scipy" |
| 1118 | + ] |
| 1119 | + }, |
| 1120 | + { |
| 1121 | + "cell_type": "markdown", |
| 1122 | + "metadata": {}, |
| 1123 | + "source": [ |
| 1124 | + "#### Q.32. Do you know any additional data structures available in the standard library?\n", |
| 1125 | + "Python's standard library has a wealth of data structures ,including:\n", |
| 1126 | + "- Bisect\n", |
| 1127 | + "- Boolean\n", |
| 1128 | + "- Deque\n", |
| 1129 | + "- Float\n", |
| 1130 | + "- Heapq\n", |
| 1131 | + "- Integers" |
| 1132 | + ] |
| 1133 | + }, |
| 1134 | + { |
| 1135 | + "cell_type": "markdown", |
| 1136 | + "metadata": {}, |
| 1137 | + "source": [ |
| 1138 | + "#### Q.33. In Python , How is Memory managed?\n", |
| 1139 | + "In python , memory is managed in a private heap space. This means that all the objects and data structures will be located in a private heap. However, the programer won't be allowed to access this heap. Instead, the python interpreter will handle it . At the same time, the core API will enable access to some Python tools for the programmer to start coding . \n", |
| 1140 | + "\n", |
| 1141 | + "The memory manager will allocate the heap space for the Python objects while the inbuilt garbage collector will recycle all the memory that's not being used to boost available heap space. " |
| 1142 | + ] |
| 1143 | + }, |
| 1144 | + { |
| 1145 | + "cell_type": "markdown", |
| 1146 | + "metadata": {}, |
| 1147 | + "source": [ |
| 1148 | + "#### Q.34. Describe how multithreading is achieved in Python\n", |
| 1149 | + "Even though Python comes with a multi-threading package, if the motive behind multithreading is to speed the code then using the package is not the go-to option.\n", |
| 1150 | + "\n", |
| 1151 | + "The package has something called the GIL or Global Interpreter Lock, which is a construct. It ensures that one and only one of the threads execute at any given time. A thread acquires the GIL and then do some work before passing it to the next thread.\n", |
| 1152 | + "\n", |
| 1153 | + "This happens so fast that to a user it seems that threads are executing in parallel. Obviously, this is not the case as they are just taking turns while using the same CPU core. Moreover, GIL passing adds to the overall overhead to the execution.\n", |
| 1154 | + "\n", |
| 1155 | + "Hence, if you intend to use the threading package for speeding up the execution, using the package is not recommended." |
| 1156 | + ] |
| 1157 | + }, |
| 1158 | + { |
| 1159 | + "cell_type": "markdown", |
| 1160 | + "metadata": {}, |
| 1161 | + "source": [ |
| 1162 | + "#### Q.35. Draw a comparison between the range and xrange in Python.\n", |
| 1163 | + "In terms of functionality, both range and xrange are identical. Both allow for generating a list of integers. The main difference between the two is that while range returns a Python list object, xrange returns an xrange object.\n", |
| 1164 | + "\n", |
| 1165 | + "Xrange is not able to generate a static list at runtime the way range does. On the contrary, it creates values along with the requirements via a special technique called yielding. It is used with a type of object known as generators.\n", |
| 1166 | + "\n", |
| 1167 | + "If you have a very enormous range for which you need to generate a list, then xrange is the function to opt for. This is especially relevant for scenarios dealing with a memory-sensitive system, such as a smartphone.\n", |
| 1168 | + "\n", |
| 1169 | + "The range is a memory beast. Using it requires much more memory, especially if the requirement is gigantic. Hence, in creating an array of integers to suit the needs, it can result in a Memory Error and ultimately lead to crashing the program." |
| 1170 | + ] |
| 1171 | + }, |
| 1172 | + { |
| 1173 | + "cell_type": "markdown", |
| 1174 | + "metadata": {}, |
| 1175 | + "source": [ |
| 1176 | + "#### Q.36. Write code to show randomizing the items of a list in place in Python along with the output." |
| 1177 | + ] |
| 1178 | + }, |
| 1179 | + { |
| 1180 | + "cell_type": "code", |
| 1181 | + "execution_count": 3, |
| 1182 | + "metadata": { |
| 1183 | + "ExecuteTime": { |
| 1184 | + "end_time": "2019-06-08T10:37:09.102927Z", |
| 1185 | + "start_time": "2019-06-08T10:37:09.098208Z" |
| 1186 | + } |
| 1187 | + }, |
| 1188 | + "outputs": [ |
| 1189 | + { |
| 1190 | + "name": "stdout", |
| 1191 | + "output_type": "stream", |
| 1192 | + "text": [ |
| 1193 | + "['HeNan', 'my', 'Province', 'is', 'hometown']\n" |
| 1194 | + ] |
| 1195 | + } |
| 1196 | + ], |
| 1197 | + "source": [ |
| 1198 | + "from random import shuffle\n", |
| 1199 | + "\n", |
| 1200 | + "info = [\"my\", 'hometown', 'is', 'HeNan', 'Province']\n", |
| 1201 | + "shuffle(info)\n", |
| 1202 | + "print(info)" |
| 1203 | + ] |
| 1204 | + }, |
| 1205 | + { |
| 1206 | + "cell_type": "markdown", |
| 1207 | + "metadata": {}, |
| 1208 | + "source": [ |
| 1209 | + "#### Q.37. Write a program in python for getting indices of N maximum values in a NumPy array." |
| 1210 | + ] |
| 1211 | + }, |
| 1212 | + { |
| 1213 | + "cell_type": "code", |
| 1214 | + "execution_count": 7, |
| 1215 | + "metadata": { |
| 1216 | + "ExecuteTime": { |
| 1217 | + "end_time": "2019-06-08T10:43:16.842033Z", |
| 1218 | + "start_time": "2019-06-08T10:43:16.837104Z" |
| 1219 | + } |
| 1220 | + }, |
| 1221 | + "outputs": [ |
| 1222 | + { |
| 1223 | + "name": "stdout", |
| 1224 | + "output_type": "stream", |
| 1225 | + "text": [ |
| 1226 | + "[4 3 1]\n" |
| 1227 | + ] |
| 1228 | + } |
| 1229 | + ], |
| 1230 | + "source": [ |
| 1231 | + "import numpy as np\n", |
| 1232 | + "array = np.array([1, 3, 2, 4, 5])\n", |
| 1233 | + "print(array.argsort()[-3:][::-1])" |
| 1234 | + ] |
| 1235 | + }, |
| 1236 | + { |
| 1237 | + "cell_type": "markdown", |
| 1238 | + "metadata": {}, |
| 1239 | + "source": [ |
| 1240 | + "#### Q.38. Whenever Python exits, all the memory isn't deallocated. Why is it so ?\n", |
| 1241 | + "\n", |
| 1242 | + "Upon existing , Python's built-in effective cleanup mechanism comes into play and try to deallocate or destroy every other object.\n", |
| 1243 | + "\n", |
| 1244 | + "However, Python modules that are having circular references to other objects or the objects that are referenced from the global namespaces aren’t always deallocated or destroyed.\n", |
| 1245 | + "\n", |
| 1246 | + "This is because it is not possible to deallocate those portions of the memory that are reserved by the C library." |
| 1247 | + ] |
| 1248 | + }, |
| 1249 | + { |
| 1250 | + "cell_type": "markdown", |
| 1251 | + "metadata": {}, |
| 1252 | + "source": [ |
| 1253 | + "#### Q.39. What do you understand by the process of compilation and linking in Python?\n", |
| 1254 | + "\n", |
| 1255 | + "In order to compile new extensions without any error, compiling and linking is used in Python. Linking initiates only and only when the compilation is complete.\n", |
| 1256 | + "\n", |
| 1257 | + "In the case of dynamic loading, the process of compilation and linking depends on the style that is provided with the concerned system. In order to provide dynamic loading of the configuration setup files and rebuilding the interpreter, the Python interpreter is used." |
| 1258 | + ] |
| 1259 | + }, |
1077 | 1260 | { |
1078 | 1261 | "cell_type": "code", |
1079 | 1262 | "execution_count": null, |
|
0 commit comments