从其他两个词典中的值创建字典

时间:2017-10-26 04:03:03

标签: python-3.x dictionary for-loop if-statement compare

问题:我想比较两个词典 - alist& blist - 并使用这些值创建一个新词典(clist)。

****请注意,alist是比较另外两个词组的结果****

最终的解决方案是:

clist = {'actual_url':['bizname','买方','日期','金额']

我尝试这样做的是

感谢您的帮助,因为我真的被卡住了!

alist = {acct_number': ['file_no', 'url', 'user', ['Biz_name', 'tool', 'date', 'amt']]}

blist = {acct_number: ['actual_case', 'actual_url']}

clist={}

for k, v in alist.item():
    for k, v in blist.item():
       if v==v:
          clist[v]:alist[v]
print(clist)

1 个答案:

答案 0 :(得分:0)

如果 //Welcome(); string playerOne = ""; bool validWord = false; string playerOneWord = ""; do { Console.WriteLine("Okay player 1 - enter your word!"); playerOne = Console.ReadLine(); if (playerOne == "") { Console.WriteLine("Please enter an actual word."); } else { playerOneWord = playerOne; validWord = true; } } while (validWord == false); char[] charPlayOne = playerOneWord.ToCharArray(); Console.WriteLine("Excellent, I'm now going to clear this chat so player 2 can't see your word!"); Thread.Sleep(3500); Console.Clear(); char[] playOneDisguised = new char []; Array.Copy(charPlayOne, playOneDisguised, 50); Console.WriteLine("Hello Player 2! Player 1 has chosen a word, the word looks like this: "); Thread.Sleep(1200); foreach (char k in playOneDisguised) { playOneDisguised[k] = Char.Parse("*") ; } Console.WriteLine(playOneDisguised); Console.ReadLine(); } static void Welcome() { Console.WriteLine("Hello and welcome to hang man!"); Thread.Sleep(1200); Console.WriteLine("This is a two player game. Make sure you have friends! unlike me..."); Thread.Sleep(3000); Console.WriteLine("The rules are simple. 1 Player chooses a word - then player 2 has to guess the letters of the word."); Thread.Sleep(5000); Console.WriteLine("Press enter to begin."); Console.ReadLine(); } 始终是列表中的第二项,则可以执行以下操作:

'actual_url'

迭代clist = {} clist[blist['acct_number'][1]] = alist['acct_number'] 中的多个项目:

alist