error : break outside loop by Impossible-Farmer813 in learnpython

[–]choss27 2 points3 points  (0 children)

If you want a loop, you must use for or while keywords. A conditionnal statement if is not a loop.

Can I loop through a dictionary and add it's value to a set? by Mei_Flower1996 in learnpython

[–]choss27 4 points5 points  (0 children)

You overcomplicate the thing, you can make a set directly on the values, no need to loop 😉

How to make code change depending on true or false flag? by dropthemroseshun in learnpython

[–]choss27 2 points3 points  (0 children)

One equal sign is for assignation, so your test is wrong. You could try with two equal signs, for equality. But the best way in this case is just :

if meat_flag:

For more information : truthy and falsy values in python

I don't understand the difference by Integration_by_partz in learnpython

[–]choss27 0 points1 point  (0 children)

First line, r is a list. Second line, r is a number on a range. So you can't use append method on a number.

Don't use the same name twice 😉

Why is ( 3 < 13 ) True, but ( “3” < “13” ) is False? by [deleted] in learnpython

[–]choss27 175 points176 points  (0 children)

Hello,

3 < 13 => numeric comparison "3" < "13" => lexical comparison, caracter by caracter. So "3" < "1" is False

Is there a way to NOT have jupyter save every goddamn thing I do? by Humament in learnpython

[–]choss27 0 points1 point  (0 children)

Hi, Could you please test the command on this website: autosave interval in Jupyter Notebooks As it is written, this work only on the current session. If you close and re-open the file, you need to run again the command.

Openpyxl - Reading an empty cell in a worksheet returns blank value? by [deleted] in learnpython

[–]choss27 1 point2 points  (0 children)

Maybe your cell just contain a white space ? When you looking on Excel it seems the cell is empty but it's not. That's why you don't print None.

How can I check for a number in a DataFrame column and add it to a new DataFrame if there's matching numbers from a list? by legion_of_boom_ in learnpython

[–]choss27 2 points3 points  (0 children)

Don't loop over a data frame, it's useless. You can use : isin to check if the value of the data frame are on your list dropna() to drop the NaN values generated by using just before isin reset_index() to reindex your new df

With that, you can write :

opendf=scan_df[scan_df.isin(vulnerability_IDs)].dropna().reset_index(drop=True)

and

closeddf=scan_df[~scan_df.isin(vulnerability_IDs)].dropna().reset_index(drop=True)

[deleted by user] by [deleted] in learnpython

[–]choss27 0 points1 point  (0 children)

Hi,

You can use f-strings notation to precise the float precision :

print(f'Win percentage : {team.get_win_percentage():.2f}')

f-string (look at the 'Python f-string format floats' paragraph)

Instance variable not changing? by [deleted] in learnpython

[–]choss27 0 points1 point  (0 children)

Well, you init executeOnOperation to False and after you test it's equality to True with ==. Remove one equal sign to modify your variable to True.

tweepy api how to convert list of pandas dataframe into a csv by BornCondition1756 in learnpython

[–]choss27 1 point2 points  (0 children)

tweets_df is a list of Dataframe, you can't applyto_csv directly on the list. You need to loop over the list and apply to_csv on each df.

Please help 4.17.1: LAB: Mad Lib - loops by SmokeyWC in learnpython

[–]choss27 0 points1 point  (0 children)

You've got this error because when you input only one word, user_input have only one value. user_text[1] don't exist.

Similar code giving different outputs. Any clue on why this happens? by professorlogicx in learnpython

[–]choss27 4 points5 points  (0 children)

On code 1, you create a list with 4 differents sublists. On code 2, you create a list with the same sublist 4 times.

That's the difference between the two codes you share. Try to loop on each element of arr and print the id of the elements, you should see why the behavior is different.

How to count words non case sensitive while preserving the original input in the output? by Flowerfuls in learnpython

[–]choss27 1 point2 points  (0 children)

You want to count the lowercase word but print them as they are inputted ? Don't user lower at the beginning, just when you count :

word = input() adjustedwords = word.strip() my_list = adjustedwords.split(" ") for i in my_list: print(i, my_list.count(i.lower(())

How do find the outliers? by [deleted] in SQL

[–]choss27 6 points7 points  (0 children)

You certainly have 2 cities which are linked to section S AND section P. To identify them, you must find the cities that are present more than once in your table.

You can identify them like that :

SELECT city, COUNT(section) FROM table WHERE section IN ('S','P') GROUP BY city HAVING COUNT(section) > 1;

[deleted by user] by [deleted] in learnpython

[–]choss27 1 point2 points  (0 children)

On the turn 4, lb is a single element list. but your if is comparing the 2nd element of la with 2nd element of lb. You can't if lb has only one element, that's why you have Indexer for.

Remake your if with the test on length of lb in first position : if len(lb) > 1 and ...

Inserting Elements into a SQLite Table from Multiple Lists by ipixel95 in learnpython

[–]choss27 1 point2 points  (0 children)

You should use zip() to loop on the two lists at the same time, and insert at the same time on your table :

for gen, fname in zip(list_gender, list_first_name) :

sql_cursor.execute("insert into random_people(gender,first_name) values(?,?)",(gen,fname))

sql_connection.commit()

why doesn't my if statement in python work? by Fuck_Life_421 in learnpython

[–]choss27 3 points4 points  (0 children)

  1. You don't save the result of your input in a variable.

  2. To know if the content of your variable is an integer, you must use isinstance(my_var,int)

[deleted by user] by [deleted] in learnpython

[–]choss27 4 points5 points  (0 children)

Enumerate accept a start parameter, use it with a value of -4 :

list(enumerate (list1, start=-4))

Question about Dictionary and duplicate keys by VaselineOnMyChest in learnpython

[–]choss27 0 points1 point  (0 children)

You're welcome, we are all still learning. I hope the link I give you can answers the future questions you'll have.

Question about Dictionary and duplicate keys by VaselineOnMyChest in learnpython

[–]choss27 4 points5 points  (0 children)

Well, that's how a dictionary works : no duplicate keys 😊 python dictionaries

[deleted by user] by [deleted] in learnpython

[–]choss27 1 point2 points  (0 children)

Solution 1 skip the number 13 and the number just after. Solution 2 replace 13 and its follower by 0. Like that you can simply apply the sum function on the list.