##### list sum gives unexpected result
 list sum gives unexpected result Nesso Unladen Swallow Posts: 1 Threads: 1 Joined: Feb 2020 Reputation: Feb-04-2020, 08:31 AM (This post was last modified: Feb-04-2020, 11:59 AM by Larz60+.) I am trying to sum some lists in order to get this result: ``````Output:\start5/8 e16 b16 c16 a2 \start3/8 e16 b2 a16 f16 \start6/8 c16 b8 \start6/8 f16 d4 b8 e16 a16 c16 \start2/8 a16 e2 f16 b4 c16 d8 \start4/8 c16 e4 a8 \start4/8 c2 f16 a4 b16 e8 ``````But instead I am getting this: ``````Output:\start5/8 \start3/8 \start6/8 \start6/8 \start2/8 \start4/8 \start4/8 e16 b16 c16 a2 e16 b2 a16 f16 c16 b8 f16 d4 b8 e16 a16 c16 a16 e2 f16 b4 c16 d8 c16 e4 a8 c2 f16 a4 b16 e8 ``````My code is : ```import random list=["a","b","c","d","e","f"] listnumb=["2","4","8","16","16","16","16","16"] cellular=" " gofirst= "" for j in range(0,7): random.shuffle(list) random.shuffle(listnumb) dur=random.randint(2,6) gofirst = "\\start" + str(dur) + "/8 " print("===============================") for i in range(0,dur): cellular=cellular+list[i]+listnumb[i%len(listnumb)] + " " cellular= gofirst + cellular + "\n" print(cellular)```Strange thing is that if I change the order on the last operation, so instead of this: cellular= gofirst + cellular + "\n" this: cellular = cellular + gofirst + "\n" It gives me this result that is the same behaviour I would have expected earlier: ``````Output:c16 d16 b16 a4 e16 f8 \start6/8 b16 c2 e8 d16 a16 f16 \start6/8 b16 d16 c16 f4 \start4/8 f16 a16 \start2/8 b4 a16 d8 f16 \start4/8 a16 f16 \start2/8 e16 a16 b8 d16 f16 c4 \start6/8 ``````Any help/ suggestion will be very appreciated Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Unexpected result linton 4 680 May-02-2020, 01:15 PM Last Post: linton Unexpected (?) result with regular expressions guraknugen 2 693 Jan-18-2020, 02:33 PM Last Post: guraknugen List comprehensions-Wrong result RavCOder 4 1,009 Oct-08-2019, 10:16 AM Last Post: RavCOder weird result trying to remove numbers from a list Exsul 6 1,240 Aug-27-2019, 05:10 AM Last Post: perfringo Dictionary adds an unexpected list erina 1 888 Mar-14-2019, 01:13 PM Last Post: ichabod801 Unexpected expected type error result MartinMaker 1 1,010 Feb-16-2019, 05:02 PM Last Post: micseydel unexpected sub result after overloading operator jolinchewjb 1 1,028 Jan-24-2019, 08:23 AM Last Post: buran Unexpected result eftimios 1 1,272 Dec-02-2018, 07:39 AM Last Post: Gribouillis Unexpected result in simple prime number example jackhj 2 1,519 Apr-20-2018, 01:48 AM Last Post: jackhj Unexpected behavior appending to a List of Dictionaries Nomad 2 1,496 Apr-03-2018, 04:22 AM Last Post: Nomad

Forum Jump:

### User Panel Messages

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