Skip to content

Programming Articles

  • HOME
  • Python
  • JavaScript
  • C/C++
  • Java
  • Terms & Conditions and Privacy Policy
  • About US
Main Menu

Python

Python

Why is it string.join(list) instead of list.join(string)?

It’s because any iterable can be joined (e.g, list, tuple, dict, set), but its contents and the “joiner” must be strings. For example: Using something other than strings will raise the following …

Why is it string.join(list) instead of list.join(string)? Learn More
Pandas

How to update the value of a row in a Python Dataframe?

In this article, we’ll learn how to update the value of a row in a Python Dataframe. If you want a direct answer and are not interested in the explanation …

How to update the value of a row in a Python Dataframe? Learn More
Python

How to read a file line-by-line into a list in Python?

This code will read the entire file into memory and remove all whitespace characters (newlines and spaces) from the end of each line: If you’re working with a large file, …

How to read a file line-by-line into a list in Python? Learn More
Python

How to remove a character from a string in Python?

In Python, you can use the replace() and translate() methods to remove characters you want to remove from a string and return a new modified string result. Strings, and especially user-generated input may contain …

How to remove a character from a string in Python? Learn More
Python

How to remove spaces from a string in python?

This article will introduce different methods to remove spaces in a messy Python string based on different scenarios and requirements. After reading, you can choose the most appropriate way for …

How to remove spaces from a string in python? Learn More
Python

How to get key with maximum value in dictionary in Python?

Sample query: I have a dictionary: keys are strings, values are integers. Example: I’d like to get ‘b’ as an answer, since it’s the key with a higher value. I did the following, …

How to get key with maximum value in dictionary in Python? Learn More
Python

How to display number with leading zeros in Python?

In Python 2 (and Python 3) you can do: Basically % is like printf or sprintf. For Python 3.+, the same behavior can also be achieved with format: Learn more about format and f-strings from this …

How to display number with leading zeros in Python? Learn More
Python

How to check if a variable exists in Python?

To check the existence of a local variable: To check the existence of a global variable: To check if an object has an attribute: How to check if a variable …

How to check if a variable exists in Python? Learn More
Python

How to run shell command and capture the output in Python?

In all officially maintained versions of Python, the simplest approach is to use the subprocess.check_output function: check_output runs a single program that takes only arguments as input.1 It returns the result exactly as printed …

How to run shell command and capture the output in Python? Learn More
Python

How to get the line count of a large file cheaply in Python?

Query statement: I need to get a line count of a large file (hundreds of thousands of lines) in python. What is the most efficient way both memory- and time-wise? …

How to get the line count of a large file cheaply in Python? Learn More
Python

How to read a text file into a string variable and strip newlines?

Sample query: I use the following code segment to read a file in python: Input file is: and when I print data I get As I see data is in list form. …

How to read a text file into a string variable and strip newlines? Learn More
Pandas

How to change column type in pandas?

Sample query: I want to convert a table, represented as a list of lists, into a Pandas DataFrame. As an extremely simplified example: What is the best way to convert the …

How to change column type in pandas? Learn More
Python / Python HowTos

How to move a file in Python?

Although os.rename() and shutil.move() will both rename files, the command that is closest to the Unix mv command is shutil.move(). The difference is that os.rename() doesn’t work if the source and destination are on different disks, while shutil.move() is …

How to move a file in Python? Learn More
Pandas

How to create a Pandas Dataframe by appending one row at a time?

In case you can get all data for the data frame upfront, there is a much faster approach than appending to a data frame: Create a list of dictionaries in …

How to create a Pandas Dataframe by appending one row at a time? Learn More
Pandas

How to add a new column to an existing DataFrame?

Sample query: I have the following indexed DataFrame with named columns and rows not- continuous numbers: I would like to add a new column, ‘e’, to the existing data frame and …

How to add a new column to an existing DataFrame? Learn More
Python

If Python is interpreted, what are .pyc files?

Query explained: I’ve been given to understand that Python is an interpreted language…However, when I look at my Python source code I see .pyc files, which Windows identifies as “Compiled Python Files”. Where do …

If Python is interpreted, what are .pyc files? Learn More
Python

How to print all the current properties and values of an object in Python

Query explained: So what I’m looking for here is something like PHP’s print_r function. This is so I can debug my scripts by seeing what’s the state of the object in question. …

How to print all the current properties and values of an object in Python Learn More

Posts navigation

1 2 … 4 Next

Featured Posts

History of UNIX

From UNIX to Linux – History of Linux

21st November 202013th November 2021

Top themes for Ubuntu

Best themes for Ubuntu: Make Ubuntu Beautiful

20th October 202029th November 2021

Strings in Python

Strings in Python

12th September 202010th November 2021

is python hard to learn

Is Python hard to learn? Top best learning resources

18th April 202013th November 2021

Recent posts

  • How to recursively grep all directories and subdirectories?
  • How to merge two Git repositories?
  • What is the main difference between an inner class and a static nested class in Java?
  • RegEx to match open tags except XHTML self-contained tags
  • How to count the occurrences of a list item in Python?
  • Why is it string.join(list) instead of list.join(string)?
Copyright © 2022 Programming Articles.
Powered by WordPress and HitMag.