Can someone help with what I want to accomplish in this python database?

Hello, I am trying to make this hypothetical database so that anything I add to jeffs_f_s, jeffs_f_m and jeffs_f_f will not be duplicated in the final output displayed as “New data added” when you run the code as well as new data count… There is initial data, and any new data added gets shown compared to the initial data (all seen in the output) I am a beginner and advice would be appreciated, thanks.

jeffs_f_s = [“hockey”] + [“basketball”]
jeffs_f_m = [“brazil man”]
jeffs_f_f = [“dragon fruit”]

data_s = [“football”, “basketball”,]
data_m = [“titanic”, “the amazing grace”,]
data_f = [“pineapple”, “banana”]

data_s1 =
data_m1 =
data_f1 =

if jeffs_f_s != “football” or jeffs_f_s != “basketball”:
data_s1.append(jeffs_f_s)
if jeffs_f_s == “basketball”:
data_s1.remove(jeffs_f_s)
data_s_new = data_s + data_s1

if jeffs_f_m != “titanic” and jeffs_f_m != “the amazing grace”:
data_m1.append(jeffs_f_m)
else:
print(“data already captured”)
data_m_new = data_m1 + data_m

if jeffs_f_f != “pineapple” and jeffs_f_f != “banana”:
data_f1.append(jeffs_f_f)
else:
print(“data already captured”)
data_f_new = data_f1 + data_f

print(“Jeffs all time sport list:”, data_s_new)
if len(data_s_new) == 0:
print(“no new data added”)
elif len(data_s_new) != 0:
print(“New data has been added:”, data_s1)
print(“Total data count:”, len(data_s_new))
print(“New data count:”, len(data_s1))
print(“Jeffs all time movie list:”, data_m_new)
if len(data_m_new) == 0:
print(“no new data added”)
elif len(data_m_new) != 0:
print(“New data has been added:”, data_m1)
print(“Total data count:”, len(data_m_new))
print(“New data count:”, len(data_m1))
if len(data_m1) == 0:
print(“no new data added”)
print(“Jeffs all time fruit list:”, data_f_new)
if len(data_f_new) == 0:
print(“no new data added”)
elif len(data_f_new) != 0:
print(“New data has been added:”, data_f1)
print(“Total data count:”, len(data_f_new))
print(“New data count:”, len(data_f1))

If you’re checking whether list jeffs_f_s doesn’t contain "football" and jeffs_f_s doesn’t contain "basketball"
you could do

if ("football" not in jeffs_f_s) and ("basketball" not in jeffs_f_s):

I recommend using loops or functions for some of the more repetitive stuff.

Here’s an example of adding a single element only if its not already in the list:

data_list = ['a', 'b', 'c']
additional = 'd'
if additional not in data:
  data_list.append(additional)
  print("added {} to data_list".format(additional))

here’s an example of adding a element from a list only if each is not already in the list:

data_list = ['a', 'b', 'c']
more = ['c', 'd']
for item in more: 
  if item not in data_list:
    data_list.append(additional)
    print("added {} to data_list".format(additional))

Imagine a data object that is stored with its key? Instead of a list, we have a dictionary comprised of key-value pairs. Every value knows its key, aka, data column in the table.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.