Python Forum
user input values into list of lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
user input values into list of lists
#1
I have the following code :

import itertools
from functools import reduce
CountOfCombination= 0
for i in itertools.product((1,2),(1,2,0),(1,2)):
       CountOfCombination += 1
       print('For combination {0} is product of values {1} and sum{2}'.format(i, reduce(lambda a, b: a*b,i),reduce(lambda a, b : a+b,i)))

print ('Count of combination is {0}'.format(CountOfCombination))
I would like to populate a variable for the cartesian product via user input, something like this :

import itertools
cont = ""
index = 0
a=[]
while (cont != "N"):
    tips = input("Input combination :  ")
    for i in range(len(tips)):
        a[index][i] = tips[i]
        index += 1
        cont = input("Contiune? [Y/N]")
where a[] would replace
(1,2),(1,2,0),(1,2)
Reply


Messages In This Thread
user input values into list of lists - by tauros73 - Dec-29-2022, 11:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove duplicates from dicts with list values wardancer84 27 847 May-27-2024, 04:54 PM
Last Post: wardancer84
Question Using Lists as Dictionary Values bfallert 8 608 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  difference between forms of input a list to function akbarza 6 1,220 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  Copying the order of another list with identical values gohanhango 7 1,305 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,370 Nov-03-2023, 05:35 PM
Last Post: huzzug
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,211 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  Comparing List values to get indexes Edward_ 7 1,334 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  restrict user input to numerical values MCL169 2 1,024 Apr-08-2023, 05:40 PM
Last Post: MCL169
  List all possibilities of a nested-list by flattened lists sparkt 1 996 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Adding values with reduce() function from the list of tuples kinimod 10 2,882 Jan-24-2023, 08:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020