menu = 0
words = ["data", "science", "happy", "smile", "lucky", "love", "dream", "yerterday", "today", "tommorrow"]
means = ["data", "science", "happiness", "smile", "lucky", "love", "dream", "yesterday", "today", "tomorrow"]
words_count=len(words)
means_count=len(means)
c=input ("Enter the word you want to delete:")
Which code should I use to delete the means value paired with the words written in c?
list
In that case, it is better to use dict.
In [1]: words = ["data", "science", "happy", "smile", "lucky", "love", "dream", "yerterday", "today", "tommorrow"]
: means = ["data", "science", "happiness", "smile", "lucky", "love", "dream", "yesterday", "today", "tomorrow"]
In [2]: pack = dict(zip(words, means))
In [3]: pack
Out[3]:
{'data': 'Data',
'Science': 'Science',
'Happy': 'Happiness',
'Smile': 'Smile',
'Lucky': 'Lucky',
'Love': 'Love',
'Dream': 'Dream',
'yesterday': 'Yesterday',
'today': 'today',
'tommorrow': 'tomorrow'}
In [4]: pack.pop('today') #todayremoved
Out[4]: 'Today'
In [5]: pack
Out[5]:
{'data': 'Data',
'Science': 'Science',
'Happy': 'Happiness',
'Smile': 'Smile',
'Lucky': 'Lucky',
'Love': 'Love',
'Dream': 'Dream',
'yesterday': 'Yesterday',
'tommorrow': 'tomorrow'}
In [6]: pack.Extract keys() # words only
Out[6]: dict_keys(['data', 'science', 'happy', 'smile', 'lucky', 'love', 'dream', 'yerterday', 'tommorrow'])
In [7]: Extract pack.values() #means only
Out [7]: dict_values (['data', 'science', 'happiness', 'smile', 'lucky', 'love', 'dream', 'yesterday', 'tomorrow'])
© 2024 OneMinuteCode. All rights reserved.