Skip to content

Tag: python

How can I handle eval() exec() multiline as first in first out

I have code from this Question: Why is Python’s eval() rejecting this multiline string, and how can I fix it? When I use this code: The result is: I am expecting this: How can I change the code? I tried to change the code, but I was not successful. Answer The code you’ve posted sorts the ast tree …

Data loss while extracting the rows from large csv file

This is in continuation from my previous question. I have 2 files, file1.csv and a large csv called master_file.csv. They have several columns and have a common column name called EMP_Code. File 1 example: EMP_name EMP_Code EMP_dept b f367 abc a c264 xyz c d264 abc master_file example: I want to extract simil…

valid and corrupt lines from file

As you can read, the function validate_data should check the imported file for corrupt and valid lines, then append them to the correct list, and print them. It works, except that, as you can probably see, the lines will not print in a single line. I’m sure I have to make two other lists to append the c…

How to create a new matrix using MIN and MAX from original array

I have a matrix named A, and I want to create a new matrix named B, where each element value is generated by this formula: B[i][j] = (A[i][j] – MIN) / (MAX – MIN), where i is the line index j is the column index. MIN is the minimum from A MAX is the value with highest value from A.

Match True in python

In JavaScript, using the switch statement, I can do the following code: And it’s going to return 1, since JavaScript switch is comparing true === (1 === 1) But the same does not happen when I try it with Python Match statement, like as follows: It returns: And another error is returned if I try it this …