[Solved] How is my “if” statement considered a SyntaxError? [closed]
Missing : to indent the if statement – if “LOL” in user_tweet: solved How is my “if” statement considered a SyntaxError? [closed]
Missing : to indent the if statement – if “LOL” in user_tweet: solved How is my “if” statement considered a SyntaxError? [closed]
You should know there are two nested list, so there should be two nested for loop to iterate the list. And you should use another for loop to iterate the split() result. The code may be like this: lines = [[‘Name0, Location0’, ‘Phone number0’], [‘Name1, Location1’, ‘Phone number1’]] result = [] for line in lines: … Read more
So effectively the set() will parse (or convert if you will) your list (or tuple) into a new “set” which will contain only distinct iterable elements. In your first list: the len = 4 as is, and is 4 with any duplicates removed (which there are not in your first list). In your second list: … Read more
You have dictionary with list so you will need for-loop (or indexes ie. [0]) to get values. And because you have nested dictionares so you will have to use all keys to get nested value. data = {‘Response’: {‘effective-configuration’: {‘default-zone-access’: 1, ‘cfg-action’: 0, ‘db-max’: 1045274, ‘db-avail’: 1041908, ‘db-committed’: 1268, ‘db-transaction’: 0, ‘db-chassis-wide-committed’: 2280, ‘transaction-token’: 0, … Read more
It strips the first two ‘[‘, it seems you have one long string, you have to split it first. datalist = data.split[‘,’] for x in datalist: # code here If you don’t want to split it and have it all in one string you need replace not strip (strip only works at the end and … Read more
You can use this snippet: def change(matrix, i, j, element): matrix[i][j] = element return matrix You don’t need a function to do this! 3 solved Changing the elements of double array [closed]
I would rewrite the main function to be something like: def GetStudentInput(): score = 0 for i in range (4): print(“Mrs Pearson’s Class Test Score Data”) name = CheckStringInput(“What’s Your Name: “) score += CheckNumericInput(“What’s Your Score: “) print(score) This eliminates the need for an extra function and avoids using a list since you don’t … Read more
You can try this: #!/bin/bash while read -r line; do date=”${line:4:8}” echo “$line” >> “${date}.txt” done < filenames.txt 0 solved Creating text files based on list of file names [closed]
that is because you have entered a wrong file mode. You used r which stands for reading while you should use the w for the writing. That code should work. a = open(“movies.txt”,”rw”) a.write(“EndGame”) a.close() 3 solved Writing and reading files [duplicate]
I can safely assume you want to know how to create a dictionary, and how to iterate through it. To create a dictionary: States = {‘Alabama’: ‘.05’, ‘Iowa’: ‘0.04’} To loop through it: for key in States: if key == stateName: #States[key] will return the value associated with the key, ex .05 for Alabama Hope … Read more
Maybe I am missing something here, but if 350 sq ft requires 1 gallon, then 250 sq ft will require 250/350 gallons. So you are being asked (I suppose) to request the area from the user and calculate the paint required for that area. wall_area=float(input(“How big is your wall in square feet? “)) gallons_paint = … Read more
try to understand your question, as far as I can do now… df = pandas.read_csv(‘your file name’,sep=’;’, header=None) df = df.groupby([1]).mean().reset_index() then pick the column you need. 2 solved How to merge data into python
Different methods can be used for removing leading and trailing spaces, for converting multiple spaces to one and to remove spaces before exclamation mark, comma etc: mystr = ” Hello . To , the world ! ” print(mystr) mystr = mystr.strip() # remove leading and trailing spaces import re # regex module mystr = re.sub(r’\s+’,” … Read more
Try this in your models: #Remove the import statement: from blog.models import sighinmodel #Then, inside your model user = models.ForeignKey(‘blog.sighinmodel’ , on_delete = None) Also, I would like to point out that this is not the correct way of importing other modules in your models.py . You should do like this: from appname.models import ModelName … Read more
The function lower returns the converted string and doesn’t convert the string self. You should use lower here: splitted = my_string.lower().split() Optimization for your code: d = {} l=[] for i,j in enumerate(splitted): l.append(d.setdefault(j, i)) with open(“numbertext.txt”,”w”) as f: f.write(str(l)) solved Can someone help me make my program case unsensitive? [closed]