[Solved] Positive and negative numbers

See let’s take a list , say sample_list sample_list = [1, 5, -9, 6, 7, -7, -2, -4, 2, 3] Or sample_list = [] while True: a = int(raw_input()) if a==0: break else:sample_list.append(a) Now, To get the length of list sample_list_length = len(sample_list) where len() is a inbuilt function which returns the length of any … Read more

[Solved] Python: Raw Input and if statements

It isn’t clear what you’re trying to achieve, but the following might give you some ideas: def select_formula(): equations = {frozenset((‘a’, ‘vi’, ‘d’ ,’t’)): ‘d = vi*t + .5*a*t^2’} variables = frozenset(input(“Enter the variables to use: “).split()) try: return equations[variables] except KeyError: return “No formula found” In use: >>> select_formula() Enter the variables to use: … Read more

[Solved] Splitting to words in a list of strings

A very minimal example: stops = {‘remove’, ‘these’, ‘words’} strings = [‘please do not remove these words’, ‘removal is not cool’, ‘please please these are the bees\’ knees’, ‘there are no stopwords here’] strings_cleaned = [‘ ‘.join(word for word in s.split() if word not in stops) for s in strings] Or you could do: strings_cleaned … Read more

[Solved] Python simple loop EOL while scanning string literal [closed]

You forgot to close your double quotes after you opened them, or maybe you put one by accident: print “(lines) Here is your edited code: myfile = open(‘log.txt’, ‘r’) count = 0 while 1: lines = myfile.readline() if not(lines): break count = count + 1 print(lines) myfile.close() A SyntaxError: EOL while scanning string literal basically … Read more

[Solved] Python: if-else statement, printing ‘Weird’ if a given integer is odd or it’s even but within a particular range shown below, and ‘Not Weird’ if not [closed]

I hope this helps! If this is not exactly what you were looking for, you can still use my code but reorganize the parts. n = int(input(‘Write your number : ‘).strip()) if n % 2 == 1: #n is odd print (“Weird”) else: #n is even if 2 <= n <= 5: #n between 2 … Read more

[Solved] I have a list, how can I split words in list to get each letter from list [closed]

You can try to use the two for approach z = [“for”, “core”, “end”] letters = [] for word in z: for element in word: letters.append(element) print(letters) #[‘f’, ‘o’, ‘r’, ‘c’, ‘o’, ‘r’, ‘e’, ‘e’, ‘n’, ‘d’] 0 solved I have a list, how can I split words in list to get each letter from … Read more

[Solved] How can I add hypen? [closed]

Is this what you needed? class Phone(): def __init__(self, name, area_code, number, is_active=True): self.name = name self.area_code = area_code self.number = number self.is_active = is_active def __str__(self): return str(self.area_code) + “-” + str(self.number)[:3]+ ‘-‘+ str(self.number)[3:] + ‘ ‘ + “(” + self.name + “)” def __repr__(self): return self.name + ‘,’+ str(self.area_code) + ‘,’ + str(self.number) … Read more

[Solved] Python. Copy Files and Folders to existing directory [closed]

You can use the copytree function from the shutil package https://docs.python.org/3/library/shutil.html#shutil.copytree. from shutil import copytree src_path = “path/of/your/source/dir” dest_path = “path/of/your/destination/dir” copytree(src_path, dest_path, dirs_exist_ok=True) The dirs_exist_ok=True parameter is useful if the dest_path already exists, and you want to overwrite the existing files. 1 solved Python. Copy Files and Folders to existing directory [closed]

[Solved] How to loop over an array of variables with the same form of name? [closed]

If you want to do all the columns in your dataframe: for col in df.columns: sns.countplot(df[col]) . Otherwise, following the pattern in your question: for i in range(1,11): column=’id_’+”{0}”.format(i).zfill(2) sns.countplot(df[column]) that will go through the numbers 1-10 and set column to the correct column name. zfill will make sure that for single digit numbers, column … Read more