In my homework, this question is asking me to make a function where Python should create dictionary of how many words that start with a certain letter in the long string is symmetrical. Symmetrical means the word starts with one letter and ends in th
Here is my list (of lists): mylist = [ [1, "John", None, "Doe"], [2, "Jane", "group1", "Zee"], [3, "Lex", "group2", "Fee"]] y = 2 for sublist in mylist: if sublist[0] == y: #
What is the equal function of PyQt setGeometry() in tkinter? Or Is there any function works like that? I searched a bit but couldn't find, all of examples looks like tkinter works on a specific widget and we just can set width-height. EDIT: The setGe
This question already has an answer here: What is the purpose of self? 17 answers In the following example employee is not used in the __init__ function, but we used it in the add_employee function calling self.employee.append(). Why is that? Why did
I have installed lxml on my AWS EC2 instance (Amazon Linux AMI), inside my virtualenv: pip3 install lxml and I got the following result: Collecting lxml Using cached lxml-3.6.0.tar.gz Installing collected packages: lxml Running setup.py install for l
# what I currently have print('你好') # 你好 # this is what I want print('你好') # \uXXXX \uXXXX How do I do this? I want to print all non-ascii characters in strings as unicode escape literalsYou can convert strings to a debug representation with non-ASCI
How would you drop / reset the column axis to shift the data down causing the column headers to be something like [0, 1, 2, 3, 4, 5] then set column headers to df[5] values? I reset the index of the rows axis all the time but never had the need to do
I just signed up here because I am taking an online course in Python and have been using this site to help me through the course. I am; however, stuck. I am not posting my actual homework assignment, but rather just an element of my code I am having
I'm working on an application using Python (3.4) and PyQt. The goal of the program is to manage and analyze large amount of data - up to ~50 binary files, which might be of total size up to 2-3 GB. When I tried to load a couple files into the program
I'm trying some basic examples from the Making Games with Python & Pygame book, but I'm facing a weird problem. Here is the example source: import pygame, time soundObj = pygame.mixer.Sound('beep.wav') soundObj.play() time.sleep(1) # wait and let the
import random print("Welcome to RNG Guesser!\n") gld = random.randrange(1,10) counter = 0 ccounter = 0 while True: print("Number of tries: {}".format(counter)) print("Number of correct guesses: {}".format(ccounter)) num = inp
I have the following code : import urllib.request try: url = "https://www.google.com/search?q=test" headers = {} usag = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0' headers['User-Agent'] = usag.encode('utf-
I've got a piece of code in a train/shipping simulation that is giving me some unexpected results. In my code, I assign functions to lambdas, archive them onto a stack, and pop off the stack, completing each function in turn. Some functions put more
I wanted to make SHA256 hasher that will save both input and output in text file. I searched stackoverflow for answers but it didn't work. I wanted it to write in the text file: all = str("At: " + date + " you have encrypted: " + text
I'm trying to create custom exit prompt dialog, which should do the following: It has Yes, No buttons along with "Save new settings" checkbox item When I click Yes, the dialog should shutdown the main program When I click No, the dialog should c
I want to print my binary tree in the following manner: 10 6 12 5 7 11 13 I have written code for insertion of nodes but can't able to write for printing the tree. so please help on this . My code is : class Node: def __init__(self,data): self.data=d
How to parse this API JSON streaming from PHP server with Python3.4? import requests import json url = 'http://api.example.com' parameters = {'code':1, 'user': 'default', 'password': 'default'} headers = {'content-type': 'application/json'} response
I'm trying to create a recursive function that checks if a grade can be converted to a float, then checks to make sure the grade is between 0 and 100. My logic as to why this would work is: Checks to see if the grade can be converted to a float. If i
I have a bytestring. It's guaranteed that it's a representation of a zip file in bytes. How can I create a zip file object in Python, knowing this bytestring?Use io.BytesIO to construct a file-like object, and then pass that object to the ZipFile con
The following example is very simple. I want to execute map() with a function which can raise Exception. It will be more clearly with an example : number_list = range(-2,8) def one_divide_by(n): return 1/n try: for number, divide in zip(number_list,
First Mystery of Strings: How come bool('foo') returns True? if 'foo' == True returns False 'foo' == False returns False 'foo' is True returns False 'foo' is False returns False Second Mystery of Integers: How come bool(5) returns True? if 5 == True
I worked on a Python 3.4 script in PyCharm 4.5. (repo: https://github.com/Djidiouf/bbot ) In it, I used import configparser without any problem for retrieving some values in a config.cfg: config = configparser.RawConfigParser() config.read('config.cf
I have a pandas dataframe of the following basic format: tempDF = pd.DataFrame({ 'id': [12,12,12,12,45,45,45,51,51,51,51,51,51,76,76,76,91,91,91,91], 'measure': [3.2,4.2,6.8,5.6,3.1,4.8,8.8,3.0,1.9,2.1,2.4,3.5,4.2,5.2,4.3,3.6,5.2,7.1,6.5,7.3], 'statu
i know how to save a users input to a text file but how do i encrypt it? here is what i have for saving a users input to text file. i tried f.encrypt("Passwords_log.txt" but had no results import time password1 = input("Please type a passwo
I use VMplayer and my OS is Lubuntu 14.04. It comes with a pre-installed python3.4.0 but I want to install python3.4.3. I downloaded the .tar.xz file from here. I then extracted the file and followed the instructions in the README: ./configure make m
The following thing really bugs me, the version of python on my laptop and the version of python inside Docker's ubuntu:trusty image are printing different results with their codecs, what is the reason for that? For example, python3 on my laptop(ubun
I created a simple app where it prints a readable information of the output of /etc/passwd, but I get an error message after parsing most entries in the file: Traceback (most recent call last): File "unpacking_args5.py", line 19, in <module&g
I'm trying to take away the brackets when creating a list. Here's my code: nums = [ 1,2 3,4,5] print (nums) output: [1,2,3,4,5] I want the single row and I want commas ... I can't figure out the rest. >>> lst = [1,2,3,4] >>> print(*lst,
### The formulas for the area and perimeter. def area(a, b, c): # calculate the sides s = (a + b + c) / 2 # calculate the area areaValue = (s*(s-a)*(s-b)*(s-c)) ** 0.5 # returning the output # Calculate the perimeter perimValue = a + b + c # returnin
Using Python 3.4, wondering how does this loop processing? while SyntaxError: print ("Hi") It's an infinite loop, how does this while loop running? It's an exception but..?Boolean value of SyntaxError is True. >>> bool(SyntaxError) True