Latest questions in Python

0 votes
1 answer

Copying files

copyfile(src, dst) This is from the shutil library https://d ...READ MORE

Jun 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
445 views
0 votes
1 answer

Creating a matrix in Python

You can create arrays of any number ...READ MORE

Jun 19, 2018 in Python by Hamartia's Mask
• 1,580 points
566 views
0 votes
1 answer

Split a string into a list of characters

This is easy. Just use the list() ...READ MORE

Jun 19, 2018 in Python by Hamartia's Mask
• 1,580 points
498 views
0 votes
1 answer

Print contents of a folder

There is a function provided in python ...READ MORE

Jun 18, 2018 in Python by Hamartia's Mask
• 1,580 points
373 views
0 votes
1 answer

Sorting a dictionary

It is not possible to sort to ...READ MORE

Jun 18, 2018 in Python by Hamartia's Mask
• 1,580 points
366 views
+3 votes
2 answers

Compiled vs Interpreted Languages

Compiled languages are written in a code ...READ MORE

Dec 3, 2018 in Python by allenvarna
• 540 points
5,147 views
0 votes
1 answer

Using sequences

Lists are like arrays, except that their ...READ MORE

Jun 14, 2018 in Python by Hamartia's Mask
• 1,580 points
563 views
0 votes
1 answer

Compare dates

>>> from datetime import datetime >>> past = ...READ MORE

Jun 14, 2018 in Python by Hamartia's Mask
• 1,580 points
505 views
0 votes
1 answer

Using exceptions in Python

They are used for control flow. Check ...READ MORE

Jun 14, 2018 in Python by Nietzsche's daemon
• 4,260 points
407 views
0 votes
1 answer

Pythonic Switch statement

You can implement it using dictionaries  def numbers_to_strings(argument): ...READ MORE

Jun 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
540 views
0 votes
1 answer

reversing a list

Use the reverse function!  list_1.reverse() READ MORE

Jun 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
387 views
0 votes
1 answer

Python Whitespace for indenting

PEP-8 recommends creating indents by tapping the ...READ MORE

Jun 12, 2018 in Python by Hamartia's Mask
• 1,580 points
421 views
0 votes
1 answer

Install mysqldb module

pip install mysqlclient READ MORE

Jun 12, 2018 in Python by Hamartia's Mask
• 1,580 points
455 views
0 votes
1 answer

Swapping values

a,b = b,a Here, python interprets the comma ...READ MORE

Jun 8, 2018 in Python by Hamartia's Mask
• 1,580 points
453 views
0 votes
1 answer

Rename a key in dict

dictionary[new_key] = dictionary.pop(old_key) READ MORE

Jun 8, 2018 in Python by Hamartia's Mask
• 1,580 points
7,879 views
0 votes
1 answer

Remove a string suffix

You can remove the substring using slicing. ...READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
824 views
0 votes
1 answer

Create an empty array

You don't have to. The size of ...READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
379 views
0 votes
1 answer

Extract element from a set without removing it

Use iter(): element = next(iter(set_1)) READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
1,005 views
0 votes
1 answer

Combine list items to a string

>>> stmt = ['this','is','a','statement'] >>> ' '.join(sentence) 'this is ...READ MORE

Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
410 views
0 votes
0 answers

Storing a list of arrays into a CSV file and retrieving it back in a different program

This is the code that I am ...READ MORE

Jun 7, 2018 in Python by aryya
• 7,450 points
2,182 views
0 votes
0 answers

Cannot make connection to .accdb file using python

I am writing a script that needs ...READ MORE

Jun 7, 2018 in Python by aryya
• 7,450 points
1,660 views
0 votes
1 answer

Normal Python code equivalent to given list comprehension

You can try this code list1=[] for i in ...READ MORE

Jun 8, 2018 in Python by jain12
• 170 points
605 views
0 votes
2 answers

Delete a character from pythons string

If you want to remove the 'J' ...READ MORE

Jun 12, 2018 in Python by anonymous
479 views
0 votes
1 answer

Binary numbers in python

>>> 0b1011 11 READ MORE

Jun 6, 2018 in Python by Hamartia's Mask
• 1,580 points
579 views
0 votes
1 answer

What are the differences between type() and isinstance()?

To summarize the contents of other (already ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,450 points
505 views
0 votes
1 answer

How to sort a list of strings?

Basic answer: mylist = ["b", "C", "A"] mylist.sort() This modifies ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,450 points
1,266 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,450 points
1,106 views
+1 vote
3 answers

Difference between append vs. extend list methods in Python

Python append() method adds an element to ...READ MORE

Aug 21, 2019 in Python by germyrinn
• 240 points
95,870 views
0 votes
1 answer

How to read/process command line arguments?

The canonical solution in the standard library ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,450 points
612 views
0 votes
1 answer

a basic question about “while true”

while True means loop forever. The while ...READ MORE

Jun 4, 2018 in Python by aryya
• 7,450 points
5,498 views
+1 vote
2 answers

How to print first character of each word in upper case of a string in Python

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s[0]              for i in range(len(s)):                     if ...READ MORE

Oct 28, 2020 in Python by Anurag
11,820 views
0 votes
1 answer

Enlarging a list using functions using append() and extend()

Let me illustrate this with an example ...READ MORE

Jun 1, 2018 in Python by Nietzsche's daemon
• 4,260 points
394 views
0 votes
1 answer

Extract all characters of a string

Convert it to a list -  s = ...READ MORE

Jun 1, 2018 in Python by Nietzsche's daemon
• 4,260 points
624 views
0 votes
2 answers

Obtaining a value when given a key in python dicionaries

Yes you can check below code dictionary = ...READ MORE

Nov 25, 2021 in Python by Suhas
612 views
0 votes
2 answers

Finding the index of a character in python string

You can use word.find('o') as well to ...READ MORE

Jun 1, 2018 in Python by george
• 200 points
1,279 views
0 votes
1 answer

What exactly does the .join() method do?

Look carefully at your output: 5wlfgALGbXOahekxSs9wlfgALGbXOahekxSs5 ^ ...READ MORE

May 31, 2018 in Python by charlie_brown
• 7,720 points
411 views
0 votes
1 answer

Multiple line comment in Python

Try this ''' This is a multiline comment. I can ...READ MORE

May 31, 2018 in Python by charlie_brown
• 7,720 points
386 views
0 votes
1 answer

Number of days between dates in Python

You can use the date module to ...READ MORE

May 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
429 views
0 votes
1 answer

Join all strings in a list of strings

s = " ".join(myList) #here " " ...READ MORE

May 30, 2018 in Python by Nietzsche's daemon
• 4,260 points
545 views
0 votes
1 answer

Replacements for switch statement in Python?

You could use a dictionary: def f(x): ...READ MORE

May 29, 2018 in Python by aryya
• 7,450 points
532 views
0 votes
1 answer

How do you get the logical xor of two variables in Python?

If you're already normalizing the inputs to ...READ MORE

May 29, 2018 in Python by aryya
• 7,450 points
10,481 views
0 votes
1 answer

Using Lists and Tuples in Python

if you are familiar with C programming, ...READ MORE

May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
738 views
0 votes
1 answer

Sorting a list of strings in Python

Use the sort function mylist.sort() READ MORE

May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
454 views
0 votes
1 answer

Looping over a string in python

for c in "string": ...READ MORE

May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
466 views
0 votes
1 answer

Comparing strings in Python

Convert both the strings to either uppercase ...READ MORE

May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
623 views
0 votes
2 answers

Splitting a Python String

The split() method in Python returns a ...READ MORE

Oct 3, 2018 in Python by anonymous
503 views
0 votes
1 answer

Size of an object in Python

Use sys.getsizeof() function: >>> import sys >>> s = ...READ MORE

May 25, 2018 in Python by Nietzsche's daemon
• 4,260 points
846 views
0 votes
1 answer

Difference between two lists in python

difference = list(set(list1) - set(list2)) READ MORE

May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,605 views
0 votes
1 answer

Create and open a file in Python

file = open('text.txt', 'w+) READ MORE

May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
712 views
0 votes
1 answer

How can I get a list of locally installed Python modules?

Solution My 50 cents for getting a pip freeze-like ...READ MORE

May 24, 2018 in Python by charlie_brown
• 7,720 points
1,038 views